{-# 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.UpdateModel
-- 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)
--
-- Changes information about a model.
module Amazonka.APIGateway.UpdateModel
  ( -- * Creating a Request
    UpdateModel (..),
    newUpdateModel,

    -- * Request Lenses
    updateModel_patchOperations,
    updateModel_restApiId,
    updateModel_modelName,

    -- * 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 update an existing model in an existing RestApi resource.
--
-- /See:/ 'newUpdateModel' smart constructor.
data UpdateModel = UpdateModel'
  { -- | A list of update operations to be applied to the specified resource and
    -- in the order specified in this list.
    UpdateModel -> Maybe [PatchOperation]
patchOperations :: Prelude.Maybe [PatchOperation],
    -- | [Required] The string identifier of the associated RestApi.
    UpdateModel -> Text
restApiId :: Prelude.Text,
    -- | [Required] The name of the model to update.
    UpdateModel -> Text
modelName :: Prelude.Text
  }
  deriving (UpdateModel -> UpdateModel -> Bool
(UpdateModel -> UpdateModel -> Bool)
-> (UpdateModel -> UpdateModel -> Bool) -> Eq UpdateModel
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateModel -> UpdateModel -> Bool
$c/= :: UpdateModel -> UpdateModel -> Bool
== :: UpdateModel -> UpdateModel -> Bool
$c== :: UpdateModel -> UpdateModel -> Bool
Prelude.Eq, ReadPrec [UpdateModel]
ReadPrec UpdateModel
Int -> ReadS UpdateModel
ReadS [UpdateModel]
(Int -> ReadS UpdateModel)
-> ReadS [UpdateModel]
-> ReadPrec UpdateModel
-> ReadPrec [UpdateModel]
-> Read UpdateModel
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateModel]
$creadListPrec :: ReadPrec [UpdateModel]
readPrec :: ReadPrec UpdateModel
$creadPrec :: ReadPrec UpdateModel
readList :: ReadS [UpdateModel]
$creadList :: ReadS [UpdateModel]
readsPrec :: Int -> ReadS UpdateModel
$creadsPrec :: Int -> ReadS UpdateModel
Prelude.Read, Int -> UpdateModel -> ShowS
[UpdateModel] -> ShowS
UpdateModel -> String
(Int -> UpdateModel -> ShowS)
-> (UpdateModel -> String)
-> ([UpdateModel] -> ShowS)
-> Show UpdateModel
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateModel] -> ShowS
$cshowList :: [UpdateModel] -> ShowS
show :: UpdateModel -> String
$cshow :: UpdateModel -> String
showsPrec :: Int -> UpdateModel -> ShowS
$cshowsPrec :: Int -> UpdateModel -> ShowS
Prelude.Show, (forall x. UpdateModel -> Rep UpdateModel x)
-> (forall x. Rep UpdateModel x -> UpdateModel)
-> Generic UpdateModel
forall x. Rep UpdateModel x -> UpdateModel
forall x. UpdateModel -> Rep UpdateModel x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateModel x -> UpdateModel
$cfrom :: forall x. UpdateModel -> Rep UpdateModel x
Prelude.Generic)

-- |
-- Create a value of 'UpdateModel' 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:
--
-- 'patchOperations', 'updateModel_patchOperations' - A list of update operations to be applied to the specified resource and
-- in the order specified in this list.
--
-- 'restApiId', 'updateModel_restApiId' - [Required] The string identifier of the associated RestApi.
--
-- 'modelName', 'updateModel_modelName' - [Required] The name of the model to update.
newUpdateModel ::
  -- | 'restApiId'
  Prelude.Text ->
  -- | 'modelName'
  Prelude.Text ->
  UpdateModel
newUpdateModel :: Text -> Text -> UpdateModel
newUpdateModel Text
pRestApiId_ Text
pModelName_ =
  UpdateModel' :: Maybe [PatchOperation] -> Text -> Text -> UpdateModel
UpdateModel'
    { $sel:patchOperations:UpdateModel' :: Maybe [PatchOperation]
patchOperations = Maybe [PatchOperation]
forall a. Maybe a
Prelude.Nothing,
      $sel:restApiId:UpdateModel' :: Text
restApiId = Text
pRestApiId_,
      $sel:modelName:UpdateModel' :: Text
modelName = Text
pModelName_
    }

-- | A list of update operations to be applied to the specified resource and
-- in the order specified in this list.
updateModel_patchOperations :: Lens.Lens' UpdateModel (Prelude.Maybe [PatchOperation])
updateModel_patchOperations :: (Maybe [PatchOperation] -> f (Maybe [PatchOperation]))
-> UpdateModel -> f UpdateModel
updateModel_patchOperations = (UpdateModel -> Maybe [PatchOperation])
-> (UpdateModel -> Maybe [PatchOperation] -> UpdateModel)
-> Lens
     UpdateModel
     UpdateModel
     (Maybe [PatchOperation])
     (Maybe [PatchOperation])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateModel' {Maybe [PatchOperation]
patchOperations :: Maybe [PatchOperation]
$sel:patchOperations:UpdateModel' :: UpdateModel -> Maybe [PatchOperation]
patchOperations} -> Maybe [PatchOperation]
patchOperations) (\s :: UpdateModel
s@UpdateModel' {} Maybe [PatchOperation]
a -> UpdateModel
s {$sel:patchOperations:UpdateModel' :: Maybe [PatchOperation]
patchOperations = Maybe [PatchOperation]
a} :: UpdateModel) ((Maybe [PatchOperation] -> f (Maybe [PatchOperation]))
 -> UpdateModel -> f UpdateModel)
-> ((Maybe [PatchOperation] -> f (Maybe [PatchOperation]))
    -> Maybe [PatchOperation] -> f (Maybe [PatchOperation]))
-> (Maybe [PatchOperation] -> f (Maybe [PatchOperation]))
-> UpdateModel
-> f UpdateModel
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [PatchOperation] [PatchOperation] [PatchOperation] [PatchOperation]
-> Iso
     (Maybe [PatchOperation])
     (Maybe [PatchOperation])
     (Maybe [PatchOperation])
     (Maybe [PatchOperation])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  [PatchOperation] [PatchOperation] [PatchOperation] [PatchOperation]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | [Required] The string identifier of the associated RestApi.
updateModel_restApiId :: Lens.Lens' UpdateModel Prelude.Text
updateModel_restApiId :: (Text -> f Text) -> UpdateModel -> f UpdateModel
updateModel_restApiId = (UpdateModel -> Text)
-> (UpdateModel -> Text -> UpdateModel)
-> Lens UpdateModel UpdateModel Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateModel' {Text
restApiId :: Text
$sel:restApiId:UpdateModel' :: UpdateModel -> Text
restApiId} -> Text
restApiId) (\s :: UpdateModel
s@UpdateModel' {} Text
a -> UpdateModel
s {$sel:restApiId:UpdateModel' :: Text
restApiId = Text
a} :: UpdateModel)

-- | [Required] The name of the model to update.
updateModel_modelName :: Lens.Lens' UpdateModel Prelude.Text
updateModel_modelName :: (Text -> f Text) -> UpdateModel -> f UpdateModel
updateModel_modelName = (UpdateModel -> Text)
-> (UpdateModel -> Text -> UpdateModel)
-> Lens UpdateModel UpdateModel Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateModel' {Text
modelName :: Text
$sel:modelName:UpdateModel' :: UpdateModel -> Text
modelName} -> Text
modelName) (\s :: UpdateModel
s@UpdateModel' {} Text
a -> UpdateModel
s {$sel:modelName:UpdateModel' :: Text
modelName = Text
a} :: UpdateModel)

instance Core.AWSRequest UpdateModel where
  type AWSResponse UpdateModel = Model
  request :: UpdateModel -> Request UpdateModel
request = Service -> UpdateModel -> Request UpdateModel
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.patchJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy UpdateModel
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse UpdateModel)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse UpdateModel))
-> Logger
-> Service
-> Proxy UpdateModel
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse UpdateModel)))
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 UpdateModel

instance Prelude.NFData UpdateModel

instance Core.ToHeaders UpdateModel where
  toHeaders :: UpdateModel -> ResponseHeaders
toHeaders =
    ResponseHeaders -> UpdateModel -> 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 UpdateModel where
  toJSON :: UpdateModel -> Value
toJSON UpdateModel' {Maybe [PatchOperation]
Text
modelName :: Text
restApiId :: Text
patchOperations :: Maybe [PatchOperation]
$sel:modelName:UpdateModel' :: UpdateModel -> Text
$sel:restApiId:UpdateModel' :: UpdateModel -> Text
$sel:patchOperations:UpdateModel' :: UpdateModel -> Maybe [PatchOperation]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"patchOperations" Text -> [PatchOperation] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              ([PatchOperation] -> Pair) -> Maybe [PatchOperation] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [PatchOperation]
patchOperations
          ]
      )

instance Core.ToPath UpdateModel where
  toPath :: UpdateModel -> ByteString
toPath UpdateModel' {Maybe [PatchOperation]
Text
modelName :: Text
restApiId :: Text
patchOperations :: Maybe [PatchOperation]
$sel:modelName:UpdateModel' :: UpdateModel -> Text
$sel:restApiId:UpdateModel' :: UpdateModel -> Text
$sel:patchOperations:UpdateModel' :: UpdateModel -> Maybe [PatchOperation]
..} =
    [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/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
modelName
      ]

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