{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.CreateModel
-- 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)
--
-- Adds a new Model resource to an existing RestApi resource.
module Amazonka.APIGateway.CreateModel
  ( -- * Creating a Request
    CreateModel (..),
    newCreateModel,

    -- * Request Lenses
    createModel_schema,
    createModel_description,
    createModel_restApiId,
    createModel_name,
    createModel_contentType,

    -- * Destructuring the Response
    Model (..),
    newModel,

    -- * Response Lenses
    model_schema,
    model_name,
    model_id,
    model_description,
    model_contentType,
  )
where

import Amazonka.APIGateway.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | Request to add a new Model to an existing RestApi resource.
--
-- /See:/ 'newCreateModel' smart constructor.
data CreateModel = CreateModel'
  { -- | 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.
    CreateModel -> Maybe Text
schema :: Prelude.Maybe Prelude.Text,
    -- | The description of the model.
    CreateModel -> Maybe Text
description :: Prelude.Maybe Prelude.Text,
    -- | [Required] The RestApi identifier under which the Model will be created.
    CreateModel -> Text
restApiId :: Prelude.Text,
    -- | [Required] The name of the model. Must be alphanumeric.
    CreateModel -> Text
name :: Prelude.Text,
    -- | [Required] The content-type for the model.
    CreateModel -> Text
contentType :: Prelude.Text
  }
  deriving (CreateModel -> CreateModel -> Bool
(CreateModel -> CreateModel -> Bool)
-> (CreateModel -> CreateModel -> Bool) -> Eq CreateModel
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateModel -> CreateModel -> Bool
$c/= :: CreateModel -> CreateModel -> Bool
== :: CreateModel -> CreateModel -> Bool
$c== :: CreateModel -> CreateModel -> Bool
Prelude.Eq, ReadPrec [CreateModel]
ReadPrec CreateModel
Int -> ReadS CreateModel
ReadS [CreateModel]
(Int -> ReadS CreateModel)
-> ReadS [CreateModel]
-> ReadPrec CreateModel
-> ReadPrec [CreateModel]
-> Read CreateModel
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateModel]
$creadListPrec :: ReadPrec [CreateModel]
readPrec :: ReadPrec CreateModel
$creadPrec :: ReadPrec CreateModel
readList :: ReadS [CreateModel]
$creadList :: ReadS [CreateModel]
readsPrec :: Int -> ReadS CreateModel
$creadsPrec :: Int -> ReadS CreateModel
Prelude.Read, Int -> CreateModel -> ShowS
[CreateModel] -> ShowS
CreateModel -> String
(Int -> CreateModel -> ShowS)
-> (CreateModel -> String)
-> ([CreateModel] -> ShowS)
-> Show CreateModel
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateModel] -> ShowS
$cshowList :: [CreateModel] -> ShowS
show :: CreateModel -> String
$cshow :: CreateModel -> String
showsPrec :: Int -> CreateModel -> ShowS
$cshowsPrec :: Int -> CreateModel -> ShowS
Prelude.Show, (forall x. CreateModel -> Rep CreateModel x)
-> (forall x. Rep CreateModel x -> CreateModel)
-> Generic CreateModel
forall x. Rep CreateModel x -> CreateModel
forall x. CreateModel -> Rep CreateModel x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateModel x -> CreateModel
$cfrom :: forall x. CreateModel -> Rep CreateModel x
Prelude.Generic)

-- |
-- Create a value of 'CreateModel' 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', 'createModel_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.
--
-- 'description', 'createModel_description' - The description of the model.
--
-- 'restApiId', 'createModel_restApiId' - [Required] The RestApi identifier under which the Model will be created.
--
-- 'name', 'createModel_name' - [Required] The name of the model. Must be alphanumeric.
--
-- 'contentType', 'createModel_contentType' - [Required] The content-type for the model.
newCreateModel ::
  -- | 'restApiId'
  Prelude.Text ->
  -- | 'name'
  Prelude.Text ->
  -- | 'contentType'
  Prelude.Text ->
  CreateModel
newCreateModel :: Text -> Text -> Text -> CreateModel
newCreateModel Text
pRestApiId_ Text
pName_ Text
pContentType_ =
  CreateModel' :: Maybe Text -> Maybe Text -> Text -> Text -> Text -> CreateModel
CreateModel'
    { $sel:schema:CreateModel' :: Maybe Text
schema = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:description:CreateModel' :: Maybe Text
description = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:restApiId:CreateModel' :: Text
restApiId = Text
pRestApiId_,
      $sel:name:CreateModel' :: Text
name = Text
pName_,
      $sel:contentType:CreateModel' :: Text
contentType = Text
pContentType_
    }

-- | 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.
createModel_schema :: Lens.Lens' CreateModel (Prelude.Maybe Prelude.Text)
createModel_schema :: (Maybe Text -> f (Maybe Text)) -> CreateModel -> f CreateModel
createModel_schema = (CreateModel -> Maybe Text)
-> (CreateModel -> Maybe Text -> CreateModel)
-> Lens CreateModel CreateModel (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateModel' {Maybe Text
schema :: Maybe Text
$sel:schema:CreateModel' :: CreateModel -> Maybe Text
schema} -> Maybe Text
schema) (\s :: CreateModel
s@CreateModel' {} Maybe Text
a -> CreateModel
s {$sel:schema:CreateModel' :: Maybe Text
schema = Maybe Text
a} :: CreateModel)

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

-- | [Required] The RestApi identifier under which the Model will be created.
createModel_restApiId :: Lens.Lens' CreateModel Prelude.Text
createModel_restApiId :: (Text -> f Text) -> CreateModel -> f CreateModel
createModel_restApiId = (CreateModel -> Text)
-> (CreateModel -> Text -> CreateModel)
-> Lens CreateModel CreateModel Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateModel' {Text
restApiId :: Text
$sel:restApiId:CreateModel' :: CreateModel -> Text
restApiId} -> Text
restApiId) (\s :: CreateModel
s@CreateModel' {} Text
a -> CreateModel
s {$sel:restApiId:CreateModel' :: Text
restApiId = Text
a} :: CreateModel)

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

-- | [Required] The content-type for the model.
createModel_contentType :: Lens.Lens' CreateModel Prelude.Text
createModel_contentType :: (Text -> f Text) -> CreateModel -> f CreateModel
createModel_contentType = (CreateModel -> Text)
-> (CreateModel -> Text -> CreateModel)
-> Lens CreateModel CreateModel Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateModel' {Text
contentType :: Text
$sel:contentType:CreateModel' :: CreateModel -> Text
contentType} -> Text
contentType) (\s :: CreateModel
s@CreateModel' {} Text
a -> CreateModel
s {$sel:contentType:CreateModel' :: Text
contentType = Text
a} :: CreateModel)

instance Core.AWSRequest CreateModel where
  type AWSResponse CreateModel = Model
  request :: CreateModel -> Request CreateModel
request = Service -> CreateModel -> Request CreateModel
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateModel
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateModel)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateModel))
-> Logger
-> Service
-> Proxy CreateModel
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse CreateModel)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      (\Int
s ResponseHeaders
h Object
x -> Object -> Either String Model
forall a. FromJSON a => Object -> Either String a
Core.eitherParseJSON Object
x)

instance Prelude.Hashable CreateModel

instance Prelude.NFData CreateModel

instance Core.ToHeaders CreateModel where
  toHeaders :: CreateModel -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateModel -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Accept"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# (ByteString
"application/json" :: Prelude.ByteString)
          ]
      )

instance Core.ToJSON CreateModel where
  toJSON :: CreateModel -> Value
toJSON CreateModel' {Maybe Text
Text
contentType :: Text
name :: Text
restApiId :: Text
description :: Maybe Text
schema :: Maybe Text
$sel:contentType:CreateModel' :: CreateModel -> Text
$sel:name:CreateModel' :: CreateModel -> Text
$sel:restApiId:CreateModel' :: CreateModel -> Text
$sel:description:CreateModel' :: CreateModel -> Maybe Text
$sel:schema:CreateModel' :: CreateModel -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"schema" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
schema,
            (Text
"description" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
description,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"contentType" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
contentType)
          ]
      )

instance Core.ToPath CreateModel where
  toPath :: CreateModel -> ByteString
toPath CreateModel' {Maybe Text
Text
contentType :: Text
name :: Text
restApiId :: Text
description :: Maybe Text
schema :: Maybe Text
$sel:contentType:CreateModel' :: CreateModel -> Text
$sel:name:CreateModel' :: CreateModel -> Text
$sel:restApiId:CreateModel' :: CreateModel -> Text
$sel:description:CreateModel' :: CreateModel -> Maybe Text
$sel:schema:CreateModel' :: CreateModel -> Maybe Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/restapis/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
restApiId, ByteString
"/models"]

instance Core.ToQuery CreateModel where
  toQuery :: CreateModel -> QueryString
toQuery = QueryString -> CreateModel -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty