{-# 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.APIGateway.Types.GatewayResponse
-- 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.APIGateway.Types.GatewayResponse where

import Amazonka.APIGateway.Types.GatewayResponseType
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

-- | A gateway response of a given response type and status code, with
-- optional response parameters and mapping templates.
--
-- /See:/ 'newGatewayResponse' smart constructor.
data GatewayResponse = GatewayResponse'
  { -- | A Boolean flag to indicate whether this GatewayResponse is the default
    -- gateway response (@true@) or not (@false@). A default gateway response
    -- is one generated by API Gateway without any customization by an API
    -- developer.
    GatewayResponse -> Maybe Bool
defaultResponse :: Prelude.Maybe Prelude.Bool,
    -- | Response parameters (paths, query strings and headers) of the
    -- GatewayResponse as a string-to-string map of key-value pairs.
    GatewayResponse -> Maybe (HashMap Text Text)
responseParameters :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | Response templates of the GatewayResponse as a string-to-string map of
    -- key-value pairs.
    GatewayResponse -> Maybe (HashMap Text Text)
responseTemplates :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The response type of the associated GatewayResponse.
    GatewayResponse -> Maybe GatewayResponseType
responseType :: Prelude.Maybe GatewayResponseType,
    -- | The HTTP status code for this GatewayResponse.
    GatewayResponse -> Maybe Text
statusCode :: Prelude.Maybe Prelude.Text
  }
  deriving (GatewayResponse -> GatewayResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GatewayResponse -> GatewayResponse -> Bool
$c/= :: GatewayResponse -> GatewayResponse -> Bool
== :: GatewayResponse -> GatewayResponse -> Bool
$c== :: GatewayResponse -> GatewayResponse -> Bool
Prelude.Eq, ReadPrec [GatewayResponse]
ReadPrec GatewayResponse
Int -> ReadS GatewayResponse
ReadS [GatewayResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GatewayResponse]
$creadListPrec :: ReadPrec [GatewayResponse]
readPrec :: ReadPrec GatewayResponse
$creadPrec :: ReadPrec GatewayResponse
readList :: ReadS [GatewayResponse]
$creadList :: ReadS [GatewayResponse]
readsPrec :: Int -> ReadS GatewayResponse
$creadsPrec :: Int -> ReadS GatewayResponse
Prelude.Read, Int -> GatewayResponse -> ShowS
[GatewayResponse] -> ShowS
GatewayResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GatewayResponse] -> ShowS
$cshowList :: [GatewayResponse] -> ShowS
show :: GatewayResponse -> String
$cshow :: GatewayResponse -> String
showsPrec :: Int -> GatewayResponse -> ShowS
$cshowsPrec :: Int -> GatewayResponse -> ShowS
Prelude.Show, forall x. Rep GatewayResponse x -> GatewayResponse
forall x. GatewayResponse -> Rep GatewayResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GatewayResponse x -> GatewayResponse
$cfrom :: forall x. GatewayResponse -> Rep GatewayResponse x
Prelude.Generic)

-- |
-- Create a value of 'GatewayResponse' 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:
--
-- 'defaultResponse', 'gatewayResponse_defaultResponse' - A Boolean flag to indicate whether this GatewayResponse is the default
-- gateway response (@true@) or not (@false@). A default gateway response
-- is one generated by API Gateway without any customization by an API
-- developer.
--
-- 'responseParameters', 'gatewayResponse_responseParameters' - Response parameters (paths, query strings and headers) of the
-- GatewayResponse as a string-to-string map of key-value pairs.
--
-- 'responseTemplates', 'gatewayResponse_responseTemplates' - Response templates of the GatewayResponse as a string-to-string map of
-- key-value pairs.
--
-- 'responseType', 'gatewayResponse_responseType' - The response type of the associated GatewayResponse.
--
-- 'statusCode', 'gatewayResponse_statusCode' - The HTTP status code for this GatewayResponse.
newGatewayResponse ::
  GatewayResponse
newGatewayResponse :: GatewayResponse
newGatewayResponse =
  GatewayResponse'
    { $sel:defaultResponse:GatewayResponse' :: Maybe Bool
defaultResponse = forall a. Maybe a
Prelude.Nothing,
      $sel:responseParameters:GatewayResponse' :: Maybe (HashMap Text Text)
responseParameters = forall a. Maybe a
Prelude.Nothing,
      $sel:responseTemplates:GatewayResponse' :: Maybe (HashMap Text Text)
responseTemplates = forall a. Maybe a
Prelude.Nothing,
      $sel:responseType:GatewayResponse' :: Maybe GatewayResponseType
responseType = forall a. Maybe a
Prelude.Nothing,
      $sel:statusCode:GatewayResponse' :: Maybe Text
statusCode = forall a. Maybe a
Prelude.Nothing
    }

-- | A Boolean flag to indicate whether this GatewayResponse is the default
-- gateway response (@true@) or not (@false@). A default gateway response
-- is one generated by API Gateway without any customization by an API
-- developer.
gatewayResponse_defaultResponse :: Lens.Lens' GatewayResponse (Prelude.Maybe Prelude.Bool)
gatewayResponse_defaultResponse :: Lens' GatewayResponse (Maybe Bool)
gatewayResponse_defaultResponse = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GatewayResponse' {Maybe Bool
defaultResponse :: Maybe Bool
$sel:defaultResponse:GatewayResponse' :: GatewayResponse -> Maybe Bool
defaultResponse} -> Maybe Bool
defaultResponse) (\s :: GatewayResponse
s@GatewayResponse' {} Maybe Bool
a -> GatewayResponse
s {$sel:defaultResponse:GatewayResponse' :: Maybe Bool
defaultResponse = Maybe Bool
a} :: GatewayResponse)

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

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

-- | The response type of the associated GatewayResponse.
gatewayResponse_responseType :: Lens.Lens' GatewayResponse (Prelude.Maybe GatewayResponseType)
gatewayResponse_responseType :: Lens' GatewayResponse (Maybe GatewayResponseType)
gatewayResponse_responseType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GatewayResponse' {Maybe GatewayResponseType
responseType :: Maybe GatewayResponseType
$sel:responseType:GatewayResponse' :: GatewayResponse -> Maybe GatewayResponseType
responseType} -> Maybe GatewayResponseType
responseType) (\s :: GatewayResponse
s@GatewayResponse' {} Maybe GatewayResponseType
a -> GatewayResponse
s {$sel:responseType:GatewayResponse' :: Maybe GatewayResponseType
responseType = Maybe GatewayResponseType
a} :: GatewayResponse)

-- | The HTTP status code for this GatewayResponse.
gatewayResponse_statusCode :: Lens.Lens' GatewayResponse (Prelude.Maybe Prelude.Text)
gatewayResponse_statusCode :: Lens' GatewayResponse (Maybe Text)
gatewayResponse_statusCode = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GatewayResponse' {Maybe Text
statusCode :: Maybe Text
$sel:statusCode:GatewayResponse' :: GatewayResponse -> Maybe Text
statusCode} -> Maybe Text
statusCode) (\s :: GatewayResponse
s@GatewayResponse' {} Maybe Text
a -> GatewayResponse
s {$sel:statusCode:GatewayResponse' :: Maybe Text
statusCode = Maybe Text
a} :: GatewayResponse)

instance Data.FromJSON GatewayResponse where
  parseJSON :: Value -> Parser GatewayResponse
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"GatewayResponse"
      ( \Object
x ->
          Maybe Bool
-> Maybe (HashMap Text Text)
-> Maybe (HashMap Text Text)
-> Maybe GatewayResponseType
-> Maybe Text
-> GatewayResponse
GatewayResponse'
            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
"defaultResponse")
            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
"responseParameters"
                            forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty
                        )
            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
"responseTemplates"
                            forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty
                        )
            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
"responseType")
            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
"statusCode")
      )

instance Prelude.Hashable GatewayResponse where
  hashWithSalt :: Int -> GatewayResponse -> Int
hashWithSalt Int
_salt GatewayResponse' {Maybe Bool
Maybe Text
Maybe (HashMap Text Text)
Maybe GatewayResponseType
statusCode :: Maybe Text
responseType :: Maybe GatewayResponseType
responseTemplates :: Maybe (HashMap Text Text)
responseParameters :: Maybe (HashMap Text Text)
defaultResponse :: Maybe Bool
$sel:statusCode:GatewayResponse' :: GatewayResponse -> Maybe Text
$sel:responseType:GatewayResponse' :: GatewayResponse -> Maybe GatewayResponseType
$sel:responseTemplates:GatewayResponse' :: GatewayResponse -> Maybe (HashMap Text Text)
$sel:responseParameters:GatewayResponse' :: GatewayResponse -> Maybe (HashMap Text Text)
$sel:defaultResponse:GatewayResponse' :: GatewayResponse -> Maybe Bool
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
defaultResponse
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
responseParameters
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
responseTemplates
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe GatewayResponseType
responseType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
statusCode

instance Prelude.NFData GatewayResponse where
  rnf :: GatewayResponse -> ()
rnf GatewayResponse' {Maybe Bool
Maybe Text
Maybe (HashMap Text Text)
Maybe GatewayResponseType
statusCode :: Maybe Text
responseType :: Maybe GatewayResponseType
responseTemplates :: Maybe (HashMap Text Text)
responseParameters :: Maybe (HashMap Text Text)
defaultResponse :: Maybe Bool
$sel:statusCode:GatewayResponse' :: GatewayResponse -> Maybe Text
$sel:responseType:GatewayResponse' :: GatewayResponse -> Maybe GatewayResponseType
$sel:responseTemplates:GatewayResponse' :: GatewayResponse -> Maybe (HashMap Text Text)
$sel:responseParameters:GatewayResponse' :: GatewayResponse -> Maybe (HashMap Text Text)
$sel:defaultResponse:GatewayResponse' :: GatewayResponse -> Maybe Bool
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
defaultResponse
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
responseParameters
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
responseTemplates
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe GatewayResponseType
responseType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
statusCode