{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.ApiGatewayV2.Types.Model
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.ApiGatewayV2.Types.Model where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Represents a data model for an API. Supported only for WebSocket APIs.
-- See
-- <https://docs.aws.amazon.com/apigateway/latest/developerguide/models-mappings.html Create Models and Mapping Templates for Request and Response Mappings>.
--
-- /See:/ 'newModel' smart constructor.
data Model = Model'
  { -- | The model identifier.
    Model -> Maybe Text
modelId :: Prelude.Maybe Prelude.Text,
    -- | The schema for the model. For application\/json models, this should be
    -- JSON schema draft 4 model.
    Model -> Maybe Text
schema :: Prelude.Maybe Prelude.Text,
    -- | The description of the model.
    Model -> Maybe Text
description :: Prelude.Maybe Prelude.Text,
    -- | The content-type for the model, for example, \"application\/json\".
    Model -> Maybe Text
contentType :: Prelude.Maybe Prelude.Text,
    -- | The name of the model. Must be alphanumeric.
    Model -> Text
name :: Prelude.Text
  }
  deriving (Model -> Model -> Bool
(Model -> Model -> Bool) -> (Model -> Model -> Bool) -> Eq Model
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Model -> Model -> Bool
$c/= :: Model -> Model -> Bool
== :: Model -> Model -> Bool
$c== :: Model -> Model -> Bool
Prelude.Eq, ReadPrec [Model]
ReadPrec Model
Int -> ReadS Model
ReadS [Model]
(Int -> ReadS Model)
-> ReadS [Model]
-> ReadPrec Model
-> ReadPrec [Model]
-> Read Model
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Model]
$creadListPrec :: ReadPrec [Model]
readPrec :: ReadPrec Model
$creadPrec :: ReadPrec Model
readList :: ReadS [Model]
$creadList :: ReadS [Model]
readsPrec :: Int -> ReadS Model
$creadsPrec :: Int -> ReadS Model
Prelude.Read, Int -> Model -> ShowS
[Model] -> ShowS
Model -> String
(Int -> Model -> ShowS)
-> (Model -> String) -> ([Model] -> ShowS) -> Show Model
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Model] -> ShowS
$cshowList :: [Model] -> ShowS
show :: Model -> String
$cshow :: Model -> String
showsPrec :: Int -> Model -> ShowS
$cshowsPrec :: Int -> Model -> ShowS
Prelude.Show, (forall x. Model -> Rep Model x)
-> (forall x. Rep Model x -> Model) -> Generic Model
forall x. Rep Model x -> Model
forall x. Model -> Rep Model x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Model x -> Model
$cfrom :: forall x. Model -> Rep Model x
Prelude.Generic)

-- |
-- Create a value of 'Model' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'modelId', 'model_modelId' - The model identifier.
--
-- 'schema', 'model_schema' - The schema for the model. For application\/json models, this should be
-- JSON schema draft 4 model.
--
-- 'description', 'model_description' - The description of the model.
--
-- 'contentType', 'model_contentType' - The content-type for the model, for example, \"application\/json\".
--
-- 'name', 'model_name' - The name of the model. Must be alphanumeric.
newModel ::
  -- | 'name'
  Prelude.Text ->
  Model
newModel :: Text -> Model
newModel Text
pName_ =
  Model' :: Maybe Text
-> Maybe Text -> Maybe Text -> Maybe Text -> Text -> Model
Model'
    { $sel:modelId:Model' :: Maybe Text
modelId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:schema:Model' :: Maybe Text
schema = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:description:Model' :: Maybe Text
description = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:contentType:Model' :: Maybe Text
contentType = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:Model' :: Text
name = Text
pName_
    }

-- | The model identifier.
model_modelId :: Lens.Lens' Model (Prelude.Maybe Prelude.Text)
model_modelId :: (Maybe Text -> f (Maybe Text)) -> Model -> f Model
model_modelId = (Model -> Maybe Text)
-> (Model -> Maybe Text -> Model)
-> Lens Model Model (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Model' {Maybe Text
modelId :: Maybe Text
$sel:modelId:Model' :: Model -> Maybe Text
modelId} -> Maybe Text
modelId) (\s :: Model
s@Model' {} Maybe Text
a -> Model
s {$sel:modelId:Model' :: Maybe Text
modelId = Maybe Text
a} :: Model)

-- | The schema for the model. For application\/json models, this should be
-- JSON schema draft 4 model.
model_schema :: Lens.Lens' Model (Prelude.Maybe Prelude.Text)
model_schema :: (Maybe Text -> f (Maybe Text)) -> Model -> f Model
model_schema = (Model -> Maybe Text)
-> (Model -> Maybe Text -> Model)
-> Lens Model Model (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Model' {Maybe Text
schema :: Maybe Text
$sel:schema:Model' :: Model -> Maybe Text
schema} -> Maybe Text
schema) (\s :: Model
s@Model' {} Maybe Text
a -> Model
s {$sel:schema:Model' :: Maybe Text
schema = Maybe Text
a} :: Model)

-- | The description of the model.
model_description :: Lens.Lens' Model (Prelude.Maybe Prelude.Text)
model_description :: (Maybe Text -> f (Maybe Text)) -> Model -> f Model
model_description = (Model -> Maybe Text)
-> (Model -> Maybe Text -> Model)
-> Lens Model Model (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Model' {Maybe Text
description :: Maybe Text
$sel:description:Model' :: Model -> Maybe Text
description} -> Maybe Text
description) (\s :: Model
s@Model' {} Maybe Text
a -> Model
s {$sel:description:Model' :: Maybe Text
description = Maybe Text
a} :: Model)

-- | The content-type for the model, for example, \"application\/json\".
model_contentType :: Lens.Lens' Model (Prelude.Maybe Prelude.Text)
model_contentType :: (Maybe Text -> f (Maybe Text)) -> Model -> f Model
model_contentType = (Model -> Maybe Text)
-> (Model -> Maybe Text -> Model)
-> Lens Model Model (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Model' {Maybe Text
contentType :: Maybe Text
$sel:contentType:Model' :: Model -> Maybe Text
contentType} -> Maybe Text
contentType) (\s :: Model
s@Model' {} Maybe Text
a -> Model
s {$sel:contentType:Model' :: Maybe Text
contentType = Maybe Text
a} :: Model)

-- | The name of the model. Must be alphanumeric.
model_name :: Lens.Lens' Model Prelude.Text
model_name :: (Text -> f Text) -> Model -> f Model
model_name = (Model -> Text)
-> (Model -> Text -> Model) -> Lens Model Model Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Model' {Text
name :: Text
$sel:name:Model' :: Model -> Text
name} -> Text
name) (\s :: Model
s@Model' {} Text
a -> Model
s {$sel:name:Model' :: Text
name = Text
a} :: Model)

instance Core.FromJSON Model where
  parseJSON :: Value -> Parser Model
parseJSON =
    String -> (Object -> Parser Model) -> Value -> Parser Model
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Model"
      ( \Object
x ->
          Maybe Text
-> Maybe Text -> Maybe Text -> Maybe Text -> Text -> Model
Model'
            (Maybe Text
 -> Maybe Text -> Maybe Text -> Maybe Text -> Text -> Model)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> Maybe Text -> Maybe Text -> Text -> Model)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"modelId")
            Parser (Maybe Text -> Maybe Text -> Maybe Text -> Text -> Model)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> Maybe Text -> Text -> Model)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"schema")
            Parser (Maybe Text -> Maybe Text -> Text -> Model)
-> Parser (Maybe Text) -> Parser (Maybe Text -> Text -> Model)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"description")
            Parser (Maybe Text -> Text -> Model)
-> Parser (Maybe Text) -> Parser (Text -> Model)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"contentType")
            Parser (Text -> Model) -> Parser Text -> Parser Model
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"name")
      )

instance Prelude.Hashable Model

instance Prelude.NFData Model