{-# 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.UpdateGatewayResponse
-- 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)
--
-- Updates a GatewayResponse of a specified response type on the given
-- RestApi.
module Amazonka.APIGateway.UpdateGatewayResponse
  ( -- * Creating a Request
    UpdateGatewayResponse (..),
    newUpdateGatewayResponse,

    -- * Request Lenses
    updateGatewayResponse_patchOperations,
    updateGatewayResponse_restApiId,
    updateGatewayResponse_responseType,

    -- * Destructuring the Response
    GatewayResponse (..),
    newGatewayResponse,

    -- * Response Lenses
    gatewayResponse_defaultResponse,
    gatewayResponse_responseTemplates,
    gatewayResponse_responseType,
    gatewayResponse_statusCode,
    gatewayResponse_responseParameters,
  )
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

-- | Updates a GatewayResponse of a specified response type on the given
-- RestApi.
--
-- /See:/ 'newUpdateGatewayResponse' smart constructor.
data UpdateGatewayResponse = UpdateGatewayResponse'
  { -- | A list of update operations to be applied to the specified resource and
    -- in the order specified in this list.
    UpdateGatewayResponse -> Maybe [PatchOperation]
patchOperations :: Prelude.Maybe [PatchOperation],
    -- | [Required] The string identifier of the associated RestApi.
    UpdateGatewayResponse -> Text
restApiId :: Prelude.Text,
    -- | [Required]
    --
    -- The response type of the associated GatewayResponse.
    UpdateGatewayResponse -> GatewayResponseType
responseType :: GatewayResponseType
  }
  deriving (UpdateGatewayResponse -> UpdateGatewayResponse -> Bool
(UpdateGatewayResponse -> UpdateGatewayResponse -> Bool)
-> (UpdateGatewayResponse -> UpdateGatewayResponse -> Bool)
-> Eq UpdateGatewayResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateGatewayResponse -> UpdateGatewayResponse -> Bool
$c/= :: UpdateGatewayResponse -> UpdateGatewayResponse -> Bool
== :: UpdateGatewayResponse -> UpdateGatewayResponse -> Bool
$c== :: UpdateGatewayResponse -> UpdateGatewayResponse -> Bool
Prelude.Eq, ReadPrec [UpdateGatewayResponse]
ReadPrec UpdateGatewayResponse
Int -> ReadS UpdateGatewayResponse
ReadS [UpdateGatewayResponse]
(Int -> ReadS UpdateGatewayResponse)
-> ReadS [UpdateGatewayResponse]
-> ReadPrec UpdateGatewayResponse
-> ReadPrec [UpdateGatewayResponse]
-> Read UpdateGatewayResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateGatewayResponse]
$creadListPrec :: ReadPrec [UpdateGatewayResponse]
readPrec :: ReadPrec UpdateGatewayResponse
$creadPrec :: ReadPrec UpdateGatewayResponse
readList :: ReadS [UpdateGatewayResponse]
$creadList :: ReadS [UpdateGatewayResponse]
readsPrec :: Int -> ReadS UpdateGatewayResponse
$creadsPrec :: Int -> ReadS UpdateGatewayResponse
Prelude.Read, Int -> UpdateGatewayResponse -> ShowS
[UpdateGatewayResponse] -> ShowS
UpdateGatewayResponse -> String
(Int -> UpdateGatewayResponse -> ShowS)
-> (UpdateGatewayResponse -> String)
-> ([UpdateGatewayResponse] -> ShowS)
-> Show UpdateGatewayResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateGatewayResponse] -> ShowS
$cshowList :: [UpdateGatewayResponse] -> ShowS
show :: UpdateGatewayResponse -> String
$cshow :: UpdateGatewayResponse -> String
showsPrec :: Int -> UpdateGatewayResponse -> ShowS
$cshowsPrec :: Int -> UpdateGatewayResponse -> ShowS
Prelude.Show, (forall x. UpdateGatewayResponse -> Rep UpdateGatewayResponse x)
-> (forall x. Rep UpdateGatewayResponse x -> UpdateGatewayResponse)
-> Generic UpdateGatewayResponse
forall x. Rep UpdateGatewayResponse x -> UpdateGatewayResponse
forall x. UpdateGatewayResponse -> Rep UpdateGatewayResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateGatewayResponse x -> UpdateGatewayResponse
$cfrom :: forall x. UpdateGatewayResponse -> Rep UpdateGatewayResponse x
Prelude.Generic)

-- |
-- Create a value of 'UpdateGatewayResponse' 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', 'updateGatewayResponse_patchOperations' - A list of update operations to be applied to the specified resource and
-- in the order specified in this list.
--
-- 'restApiId', 'updateGatewayResponse_restApiId' - [Required] The string identifier of the associated RestApi.
--
-- 'responseType', 'updateGatewayResponse_responseType' - [Required]
--
-- The response type of the associated GatewayResponse.
newUpdateGatewayResponse ::
  -- | 'restApiId'
  Prelude.Text ->
  -- | 'responseType'
  GatewayResponseType ->
  UpdateGatewayResponse
newUpdateGatewayResponse :: Text -> GatewayResponseType -> UpdateGatewayResponse
newUpdateGatewayResponse Text
pRestApiId_ GatewayResponseType
pResponseType_ =
  UpdateGatewayResponse' :: Maybe [PatchOperation]
-> Text -> GatewayResponseType -> UpdateGatewayResponse
UpdateGatewayResponse'
    { $sel:patchOperations:UpdateGatewayResponse' :: Maybe [PatchOperation]
patchOperations =
        Maybe [PatchOperation]
forall a. Maybe a
Prelude.Nothing,
      $sel:restApiId:UpdateGatewayResponse' :: Text
restApiId = Text
pRestApiId_,
      $sel:responseType:UpdateGatewayResponse' :: GatewayResponseType
responseType = GatewayResponseType
pResponseType_
    }

-- | A list of update operations to be applied to the specified resource and
-- in the order specified in this list.
updateGatewayResponse_patchOperations :: Lens.Lens' UpdateGatewayResponse (Prelude.Maybe [PatchOperation])
updateGatewayResponse_patchOperations :: (Maybe [PatchOperation] -> f (Maybe [PatchOperation]))
-> UpdateGatewayResponse -> f UpdateGatewayResponse
updateGatewayResponse_patchOperations = (UpdateGatewayResponse -> Maybe [PatchOperation])
-> (UpdateGatewayResponse
    -> Maybe [PatchOperation] -> UpdateGatewayResponse)
-> Lens
     UpdateGatewayResponse
     UpdateGatewayResponse
     (Maybe [PatchOperation])
     (Maybe [PatchOperation])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateGatewayResponse' {Maybe [PatchOperation]
patchOperations :: Maybe [PatchOperation]
$sel:patchOperations:UpdateGatewayResponse' :: UpdateGatewayResponse -> Maybe [PatchOperation]
patchOperations} -> Maybe [PatchOperation]
patchOperations) (\s :: UpdateGatewayResponse
s@UpdateGatewayResponse' {} Maybe [PatchOperation]
a -> UpdateGatewayResponse
s {$sel:patchOperations:UpdateGatewayResponse' :: Maybe [PatchOperation]
patchOperations = Maybe [PatchOperation]
a} :: UpdateGatewayResponse) ((Maybe [PatchOperation] -> f (Maybe [PatchOperation]))
 -> UpdateGatewayResponse -> f UpdateGatewayResponse)
-> ((Maybe [PatchOperation] -> f (Maybe [PatchOperation]))
    -> Maybe [PatchOperation] -> f (Maybe [PatchOperation]))
-> (Maybe [PatchOperation] -> f (Maybe [PatchOperation]))
-> UpdateGatewayResponse
-> f UpdateGatewayResponse
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.
updateGatewayResponse_restApiId :: Lens.Lens' UpdateGatewayResponse Prelude.Text
updateGatewayResponse_restApiId :: (Text -> f Text)
-> UpdateGatewayResponse -> f UpdateGatewayResponse
updateGatewayResponse_restApiId = (UpdateGatewayResponse -> Text)
-> (UpdateGatewayResponse -> Text -> UpdateGatewayResponse)
-> Lens UpdateGatewayResponse UpdateGatewayResponse Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateGatewayResponse' {Text
restApiId :: Text
$sel:restApiId:UpdateGatewayResponse' :: UpdateGatewayResponse -> Text
restApiId} -> Text
restApiId) (\s :: UpdateGatewayResponse
s@UpdateGatewayResponse' {} Text
a -> UpdateGatewayResponse
s {$sel:restApiId:UpdateGatewayResponse' :: Text
restApiId = Text
a} :: UpdateGatewayResponse)

-- | [Required]
--
-- The response type of the associated GatewayResponse.
updateGatewayResponse_responseType :: Lens.Lens' UpdateGatewayResponse GatewayResponseType
updateGatewayResponse_responseType :: (GatewayResponseType -> f GatewayResponseType)
-> UpdateGatewayResponse -> f UpdateGatewayResponse
updateGatewayResponse_responseType = (UpdateGatewayResponse -> GatewayResponseType)
-> (UpdateGatewayResponse
    -> GatewayResponseType -> UpdateGatewayResponse)
-> Lens
     UpdateGatewayResponse
     UpdateGatewayResponse
     GatewayResponseType
     GatewayResponseType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateGatewayResponse' {GatewayResponseType
responseType :: GatewayResponseType
$sel:responseType:UpdateGatewayResponse' :: UpdateGatewayResponse -> GatewayResponseType
responseType} -> GatewayResponseType
responseType) (\s :: UpdateGatewayResponse
s@UpdateGatewayResponse' {} GatewayResponseType
a -> UpdateGatewayResponse
s {$sel:responseType:UpdateGatewayResponse' :: GatewayResponseType
responseType = GatewayResponseType
a} :: UpdateGatewayResponse)

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

instance Prelude.Hashable UpdateGatewayResponse

instance Prelude.NFData UpdateGatewayResponse

instance Core.ToHeaders UpdateGatewayResponse where
  toHeaders :: UpdateGatewayResponse -> ResponseHeaders
toHeaders =
    ResponseHeaders -> UpdateGatewayResponse -> 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 UpdateGatewayResponse where
  toJSON :: UpdateGatewayResponse -> Value
toJSON UpdateGatewayResponse' {Maybe [PatchOperation]
Text
GatewayResponseType
responseType :: GatewayResponseType
restApiId :: Text
patchOperations :: Maybe [PatchOperation]
$sel:responseType:UpdateGatewayResponse' :: UpdateGatewayResponse -> GatewayResponseType
$sel:restApiId:UpdateGatewayResponse' :: UpdateGatewayResponse -> Text
$sel:patchOperations:UpdateGatewayResponse' :: UpdateGatewayResponse -> 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 UpdateGatewayResponse where
  toPath :: UpdateGatewayResponse -> ByteString
toPath UpdateGatewayResponse' {Maybe [PatchOperation]
Text
GatewayResponseType
responseType :: GatewayResponseType
restApiId :: Text
patchOperations :: Maybe [PatchOperation]
$sel:responseType:UpdateGatewayResponse' :: UpdateGatewayResponse -> GatewayResponseType
$sel:restApiId:UpdateGatewayResponse' :: UpdateGatewayResponse -> Text
$sel:patchOperations:UpdateGatewayResponse' :: UpdateGatewayResponse -> 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
"/gatewayresponses/",
        GatewayResponseType -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS GatewayResponseType
responseType
      ]

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