{-# 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.APIGateway.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.APIGateway.Types.Model where

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

-- | Represents the data structure of a method\'s request or response
-- payload.
--
-- A request model defines the data structure of the client-supplied
-- request payload. A response model defines the data structure of the
-- response payload returned by the back end. Although not required, models
-- are useful for mapping payloads between the front end and back end.
--
-- A model is used for generating an API\'s SDK, validating the input
-- request body, and creating a skeletal mapping template.
--
-- Method, MethodResponse,
-- <https://docs.aws.amazon.com/apigateway/latest/developerguide/models-mappings.html Models and Mappings>
--
-- /See:/ 'newModel' smart constructor.
data Model = Model'
  { -- | The schema for the model. For @application\/json@ models, this should be
    -- <https://tools.ietf.org/html/draft-zyp-json-schema-04 JSON schema draft 4>
    -- model. Do not include \"\\*\/\" characters in the description of any
    -- properties because such \"\\*\/\" characters may be interpreted as the
    -- closing marker for comments in some languages, such as Java or
    -- JavaScript, causing the installation of your API\'s SDK generated by API
    -- Gateway to fail.
    Model -> Maybe Text
schema :: Prelude.Maybe Prelude.Text,
    -- | The name of the model. Must be an alphanumeric string.
    Model -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | The identifier for the model resource.
    Model -> Maybe Text
id :: Prelude.Maybe Prelude.Text,
    -- | The description of the model.
    Model -> Maybe Text
description :: Prelude.Maybe Prelude.Text,
    -- | The content-type for the model.
    Model -> Maybe Text
contentType :: Prelude.Maybe 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:
--
-- 'schema', 'model_schema' - The schema for the model. For @application\/json@ models, this should be
-- <https://tools.ietf.org/html/draft-zyp-json-schema-04 JSON schema draft 4>
-- model. Do not include \"\\*\/\" characters in the description of any
-- properties because such \"\\*\/\" characters may be interpreted as the
-- closing marker for comments in some languages, such as Java or
-- JavaScript, causing the installation of your API\'s SDK generated by API
-- Gateway to fail.
--
-- 'name', 'model_name' - The name of the model. Must be an alphanumeric string.
--
-- 'id', 'model_id' - The identifier for the model resource.
--
-- 'description', 'model_description' - The description of the model.
--
-- 'contentType', 'model_contentType' - The content-type for the model.
newModel ::
  Model
newModel :: Model
newModel =
  Model' :: Maybe Text
-> Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> Model
Model'
    { $sel:schema:Model' :: Maybe Text
schema = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:Model' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:id:Model' :: Maybe Text
id = 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
    }

-- | The schema for the model. For @application\/json@ models, this should be
-- <https://tools.ietf.org/html/draft-zyp-json-schema-04 JSON schema draft 4>
-- model. Do not include \"\\*\/\" characters in the description of any
-- properties because such \"\\*\/\" characters may be interpreted as the
-- closing marker for comments in some languages, such as Java or
-- JavaScript, causing the installation of your API\'s SDK generated by API
-- Gateway to fail.
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 name of the model. Must be an alphanumeric string.
model_name :: Lens.Lens' Model (Prelude.Maybe Prelude.Text)
model_name :: (Maybe Text -> f (Maybe Text)) -> Model -> f Model
model_name = (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
name :: Maybe Text
$sel:name:Model' :: Model -> Maybe Text
name} -> Maybe Text
name) (\s :: Model
s@Model' {} Maybe Text
a -> Model
s {$sel:name:Model' :: Maybe Text
name = Maybe Text
a} :: Model)

-- | The identifier for the model resource.
model_id :: Lens.Lens' Model (Prelude.Maybe Prelude.Text)
model_id :: (Maybe Text -> f (Maybe Text)) -> Model -> f Model
model_id = (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
id :: Maybe Text
$sel:id:Model' :: Model -> Maybe Text
id} -> Maybe Text
id) (\s :: Model
s@Model' {} Maybe Text
a -> Model
s {$sel:id:Model' :: Maybe Text
id = 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.
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)

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 -> Maybe Text -> Model
Model'
            (Maybe Text
 -> Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> Model)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text -> Maybe Text -> Maybe Text -> Maybe 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
"schema")
            Parser
  (Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> Model)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> Maybe Text -> Maybe 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
"name")
            Parser (Maybe Text -> Maybe Text -> Maybe Text -> Model)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> Maybe 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
"id")
            Parser (Maybe Text -> Maybe Text -> Model)
-> Parser (Maybe Text) -> Parser (Maybe 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 -> Model) -> Parser (Maybe Text) -> Parser 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")
      )

instance Prelude.Hashable Model

instance Prelude.NFData Model