{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.ApiGatewayV2.Types.Model where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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 content-type for the model, for example, \"application\/json\".
    Model -> Maybe Text
contentType :: Prelude.Maybe Prelude.Text,
    -- | The description of the model.
    Model -> Maybe Text
description :: Prelude.Maybe Prelude.Text,
    -- | 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 name of the model. Must be alphanumeric.
    Model -> Text
name :: Prelude.Text
  }
  deriving (Model -> Model -> Bool
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]
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
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. 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:
--
-- 'contentType', 'model_contentType' - The content-type for the model, for example, \"application\/json\".
--
-- 'description', 'model_description' - The description of the model.
--
-- '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.
--
-- 'name', 'model_name' - The name of the model. Must be alphanumeric.
newModel ::
  -- | 'name'
  Prelude.Text ->
  Model
newModel :: Text -> Model
newModel Text
pName_ =
  Model'
    { $sel:contentType:Model' :: Maybe Text
contentType = forall a. Maybe a
Prelude.Nothing,
      $sel:description:Model' :: Maybe Text
description = forall a. Maybe a
Prelude.Nothing,
      $sel:modelId:Model' :: Maybe Text
modelId = forall a. Maybe a
Prelude.Nothing,
      $sel:schema:Model' :: Maybe Text
schema = forall a. Maybe a
Prelude.Nothing,
      $sel:name:Model' :: Text
name = Text
pName_
    }

-- | The content-type for the model, for example, \"application\/json\".
model_contentType :: Lens.Lens' Model (Prelude.Maybe Prelude.Text)
model_contentType :: Lens' Model (Maybe Text)
model_contentType = 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 description of the model.
model_description :: Lens.Lens' Model (Prelude.Maybe Prelude.Text)
model_description :: Lens' Model (Maybe Text)
model_description = 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 model identifier.
model_modelId :: Lens.Lens' Model (Prelude.Maybe Prelude.Text)
model_modelId :: Lens' Model (Maybe Text)
model_modelId = 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 :: Lens' Model (Maybe Text)
model_schema = 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 alphanumeric.
model_name :: Lens.Lens' Model Prelude.Text
model_name :: Lens' Model Text
model_name = 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 Data.FromJSON Model where
  parseJSON :: Value -> Parser Model
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Model"
      ( \Object
x ->
          Maybe Text
-> Maybe Text -> Maybe Text -> Maybe Text -> Text -> Model
Model'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"contentType")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"description")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"modelId")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"schema")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"name")
      )

instance Prelude.Hashable Model where
  hashWithSalt :: Int -> Model -> Int
hashWithSalt Int
_salt Model' {Maybe Text
Text
name :: Text
schema :: Maybe Text
modelId :: Maybe Text
description :: Maybe Text
contentType :: Maybe Text
$sel:name:Model' :: Model -> Text
$sel:schema:Model' :: Model -> Maybe Text
$sel:modelId:Model' :: Model -> Maybe Text
$sel:description:Model' :: Model -> Maybe Text
$sel:contentType:Model' :: Model -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
contentType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
description
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
modelId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
schema
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name

instance Prelude.NFData Model where
  rnf :: Model -> ()
rnf Model' {Maybe Text
Text
name :: Text
schema :: Maybe Text
modelId :: Maybe Text
description :: Maybe Text
contentType :: Maybe Text
$sel:name:Model' :: Model -> Text
$sel:schema:Model' :: Model -> Maybe Text
$sel:modelId:Model' :: Model -> Maybe Text
$sel:description:Model' :: Model -> Maybe Text
$sel:contentType:Model' :: Model -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
contentType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
description
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
modelId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
schema
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name