{-# 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.PutGatewayResponse
-- 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)
--
-- Creates a customization of a GatewayResponse of a specified response
-- type and status code on the given RestApi.
module Amazonka.APIGateway.PutGatewayResponse
  ( -- * Creating a Request
    PutGatewayResponse (..),
    newPutGatewayResponse,

    -- * Request Lenses
    putGatewayResponse_responseTemplates,
    putGatewayResponse_statusCode,
    putGatewayResponse_responseParameters,
    putGatewayResponse_restApiId,
    putGatewayResponse_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

-- | Creates a customization of a GatewayResponse of a specified response
-- type and status code on the given RestApi.
--
-- /See:/ 'newPutGatewayResponse' smart constructor.
data PutGatewayResponse = PutGatewayResponse'
  { -- | Response templates of the GatewayResponse as a string-to-string map of
    -- key-value pairs.
    PutGatewayResponse -> Maybe (HashMap Text Text)
responseTemplates :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The HTTP status code of the GatewayResponse.
    PutGatewayResponse -> Maybe Text
statusCode :: Prelude.Maybe Prelude.Text,
    -- | Response parameters (paths, query strings and headers) of the
    -- GatewayResponse as a string-to-string map of key-value pairs.
    PutGatewayResponse -> Maybe (HashMap Text Text)
responseParameters :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | [Required] The string identifier of the associated RestApi.
    PutGatewayResponse -> Text
restApiId :: Prelude.Text,
    -- | [Required]
    --
    -- The response type of the associated GatewayResponse.
    PutGatewayResponse -> GatewayResponseType
responseType :: GatewayResponseType
  }
  deriving (PutGatewayResponse -> PutGatewayResponse -> Bool
(PutGatewayResponse -> PutGatewayResponse -> Bool)
-> (PutGatewayResponse -> PutGatewayResponse -> Bool)
-> Eq PutGatewayResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutGatewayResponse -> PutGatewayResponse -> Bool
$c/= :: PutGatewayResponse -> PutGatewayResponse -> Bool
== :: PutGatewayResponse -> PutGatewayResponse -> Bool
$c== :: PutGatewayResponse -> PutGatewayResponse -> Bool
Prelude.Eq, ReadPrec [PutGatewayResponse]
ReadPrec PutGatewayResponse
Int -> ReadS PutGatewayResponse
ReadS [PutGatewayResponse]
(Int -> ReadS PutGatewayResponse)
-> ReadS [PutGatewayResponse]
-> ReadPrec PutGatewayResponse
-> ReadPrec [PutGatewayResponse]
-> Read PutGatewayResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PutGatewayResponse]
$creadListPrec :: ReadPrec [PutGatewayResponse]
readPrec :: ReadPrec PutGatewayResponse
$creadPrec :: ReadPrec PutGatewayResponse
readList :: ReadS [PutGatewayResponse]
$creadList :: ReadS [PutGatewayResponse]
readsPrec :: Int -> ReadS PutGatewayResponse
$creadsPrec :: Int -> ReadS PutGatewayResponse
Prelude.Read, Int -> PutGatewayResponse -> ShowS
[PutGatewayResponse] -> ShowS
PutGatewayResponse -> String
(Int -> PutGatewayResponse -> ShowS)
-> (PutGatewayResponse -> String)
-> ([PutGatewayResponse] -> ShowS)
-> Show PutGatewayResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutGatewayResponse] -> ShowS
$cshowList :: [PutGatewayResponse] -> ShowS
show :: PutGatewayResponse -> String
$cshow :: PutGatewayResponse -> String
showsPrec :: Int -> PutGatewayResponse -> ShowS
$cshowsPrec :: Int -> PutGatewayResponse -> ShowS
Prelude.Show, (forall x. PutGatewayResponse -> Rep PutGatewayResponse x)
-> (forall x. Rep PutGatewayResponse x -> PutGatewayResponse)
-> Generic PutGatewayResponse
forall x. Rep PutGatewayResponse x -> PutGatewayResponse
forall x. PutGatewayResponse -> Rep PutGatewayResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutGatewayResponse x -> PutGatewayResponse
$cfrom :: forall x. PutGatewayResponse -> Rep PutGatewayResponse x
Prelude.Generic)

-- |
-- Create a value of 'PutGatewayResponse' 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:
--
-- 'responseTemplates', 'putGatewayResponse_responseTemplates' - Response templates of the GatewayResponse as a string-to-string map of
-- key-value pairs.
--
-- 'statusCode', 'putGatewayResponse_statusCode' - The HTTP status code of the GatewayResponse.
--
-- 'responseParameters', 'putGatewayResponse_responseParameters' - Response parameters (paths, query strings and headers) of the
-- GatewayResponse as a string-to-string map of key-value pairs.
--
-- 'restApiId', 'putGatewayResponse_restApiId' - [Required] The string identifier of the associated RestApi.
--
-- 'responseType', 'putGatewayResponse_responseType' - [Required]
--
-- The response type of the associated GatewayResponse.
newPutGatewayResponse ::
  -- | 'restApiId'
  Prelude.Text ->
  -- | 'responseType'
  GatewayResponseType ->
  PutGatewayResponse
newPutGatewayResponse :: Text -> GatewayResponseType -> PutGatewayResponse
newPutGatewayResponse Text
pRestApiId_ GatewayResponseType
pResponseType_ =
  PutGatewayResponse' :: Maybe (HashMap Text Text)
-> Maybe Text
-> Maybe (HashMap Text Text)
-> Text
-> GatewayResponseType
-> PutGatewayResponse
PutGatewayResponse'
    { $sel:responseTemplates:PutGatewayResponse' :: Maybe (HashMap Text Text)
responseTemplates =
        Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:statusCode:PutGatewayResponse' :: Maybe Text
statusCode = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:responseParameters:PutGatewayResponse' :: Maybe (HashMap Text Text)
responseParameters = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:restApiId:PutGatewayResponse' :: Text
restApiId = Text
pRestApiId_,
      $sel:responseType:PutGatewayResponse' :: GatewayResponseType
responseType = GatewayResponseType
pResponseType_
    }

-- | Response templates of the GatewayResponse as a string-to-string map of
-- key-value pairs.
putGatewayResponse_responseTemplates :: Lens.Lens' PutGatewayResponse (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
putGatewayResponse_responseTemplates :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> PutGatewayResponse -> f PutGatewayResponse
putGatewayResponse_responseTemplates = (PutGatewayResponse -> Maybe (HashMap Text Text))
-> (PutGatewayResponse
    -> Maybe (HashMap Text Text) -> PutGatewayResponse)
-> Lens
     PutGatewayResponse
     PutGatewayResponse
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutGatewayResponse' {Maybe (HashMap Text Text)
responseTemplates :: Maybe (HashMap Text Text)
$sel:responseTemplates:PutGatewayResponse' :: PutGatewayResponse -> Maybe (HashMap Text Text)
responseTemplates} -> Maybe (HashMap Text Text)
responseTemplates) (\s :: PutGatewayResponse
s@PutGatewayResponse' {} Maybe (HashMap Text Text)
a -> PutGatewayResponse
s {$sel:responseTemplates:PutGatewayResponse' :: Maybe (HashMap Text Text)
responseTemplates = Maybe (HashMap Text Text)
a} :: PutGatewayResponse) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> PutGatewayResponse -> f PutGatewayResponse)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> PutGatewayResponse
-> f PutGatewayResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
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
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The HTTP status code of the GatewayResponse.
putGatewayResponse_statusCode :: Lens.Lens' PutGatewayResponse (Prelude.Maybe Prelude.Text)
putGatewayResponse_statusCode :: (Maybe Text -> f (Maybe Text))
-> PutGatewayResponse -> f PutGatewayResponse
putGatewayResponse_statusCode = (PutGatewayResponse -> Maybe Text)
-> (PutGatewayResponse -> Maybe Text -> PutGatewayResponse)
-> Lens
     PutGatewayResponse PutGatewayResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutGatewayResponse' {Maybe Text
statusCode :: Maybe Text
$sel:statusCode:PutGatewayResponse' :: PutGatewayResponse -> Maybe Text
statusCode} -> Maybe Text
statusCode) (\s :: PutGatewayResponse
s@PutGatewayResponse' {} Maybe Text
a -> PutGatewayResponse
s {$sel:statusCode:PutGatewayResponse' :: Maybe Text
statusCode = Maybe Text
a} :: PutGatewayResponse)

-- | Response parameters (paths, query strings and headers) of the
-- GatewayResponse as a string-to-string map of key-value pairs.
putGatewayResponse_responseParameters :: Lens.Lens' PutGatewayResponse (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
putGatewayResponse_responseParameters :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> PutGatewayResponse -> f PutGatewayResponse
putGatewayResponse_responseParameters = (PutGatewayResponse -> Maybe (HashMap Text Text))
-> (PutGatewayResponse
    -> Maybe (HashMap Text Text) -> PutGatewayResponse)
-> Lens
     PutGatewayResponse
     PutGatewayResponse
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutGatewayResponse' {Maybe (HashMap Text Text)
responseParameters :: Maybe (HashMap Text Text)
$sel:responseParameters:PutGatewayResponse' :: PutGatewayResponse -> Maybe (HashMap Text Text)
responseParameters} -> Maybe (HashMap Text Text)
responseParameters) (\s :: PutGatewayResponse
s@PutGatewayResponse' {} Maybe (HashMap Text Text)
a -> PutGatewayResponse
s {$sel:responseParameters:PutGatewayResponse' :: Maybe (HashMap Text Text)
responseParameters = Maybe (HashMap Text Text)
a} :: PutGatewayResponse) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> PutGatewayResponse -> f PutGatewayResponse)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> PutGatewayResponse
-> f PutGatewayResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
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
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
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.
putGatewayResponse_restApiId :: Lens.Lens' PutGatewayResponse Prelude.Text
putGatewayResponse_restApiId :: (Text -> f Text) -> PutGatewayResponse -> f PutGatewayResponse
putGatewayResponse_restApiId = (PutGatewayResponse -> Text)
-> (PutGatewayResponse -> Text -> PutGatewayResponse)
-> Lens PutGatewayResponse PutGatewayResponse Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutGatewayResponse' {Text
restApiId :: Text
$sel:restApiId:PutGatewayResponse' :: PutGatewayResponse -> Text
restApiId} -> Text
restApiId) (\s :: PutGatewayResponse
s@PutGatewayResponse' {} Text
a -> PutGatewayResponse
s {$sel:restApiId:PutGatewayResponse' :: Text
restApiId = Text
a} :: PutGatewayResponse)

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

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

instance Prelude.NFData PutGatewayResponse

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

instance Core.ToPath PutGatewayResponse where
  toPath :: PutGatewayResponse -> ByteString
toPath PutGatewayResponse' {Maybe Text
Maybe (HashMap Text Text)
Text
GatewayResponseType
responseType :: GatewayResponseType
restApiId :: Text
responseParameters :: Maybe (HashMap Text Text)
statusCode :: Maybe Text
responseTemplates :: Maybe (HashMap Text Text)
$sel:responseType:PutGatewayResponse' :: PutGatewayResponse -> GatewayResponseType
$sel:restApiId:PutGatewayResponse' :: PutGatewayResponse -> Text
$sel:responseParameters:PutGatewayResponse' :: PutGatewayResponse -> Maybe (HashMap Text Text)
$sel:statusCode:PutGatewayResponse' :: PutGatewayResponse -> Maybe Text
$sel:responseTemplates:PutGatewayResponse' :: PutGatewayResponse -> Maybe (HashMap Text 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
"/gatewayresponses/",
        GatewayResponseType -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS GatewayResponseType
responseType
      ]

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