{-# 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.MethodResponse
-- 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.MethodResponse where

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

-- | Represents a method response of a given HTTP status code returned to the
-- client. The method response is passed from the back end through the
-- associated integration response that can be transformed using a mapping
-- template.
--
-- /See:/ 'newMethodResponse' smart constructor.
data MethodResponse = MethodResponse'
  { -- | Specifies the Model resources used for the response\'s content-type.
    -- Response models are represented as a key\/value map, with a content-type
    -- as the key and a Model name as the value.
    MethodResponse -> Maybe (HashMap Text Text)
responseModels :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | A key-value map specifying required or optional response parameters that
    -- API Gateway can send back to the caller. A key defines a method response
    -- header and the value specifies whether the associated method response
    -- header is required or not. The expression of the key must match the
    -- pattern @method.response.header.{name}@, where @name@ is a valid and
    -- unique header name. API Gateway passes certain integration response data
    -- to the method response headers specified here according to the mapping
    -- you prescribe in the API\'s IntegrationResponse. The integration
    -- response data that can be mapped include an integration response header
    -- expressed in @integration.response.header.{name}@, a static value
    -- enclosed within a pair of single quotes (e.g., @\'application\/json\'@),
    -- or a JSON expression from the back-end response payload in the form of
    -- @integration.response.body.{JSON-expression}@, where @JSON-expression@
    -- is a valid JSON expression without the @$@ prefix.)
    MethodResponse -> Maybe (HashMap Text Bool)
responseParameters :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Bool),
    -- | The method response\'s status code.
    MethodResponse -> Maybe Text
statusCode :: Prelude.Maybe Prelude.Text
  }
  deriving (MethodResponse -> MethodResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MethodResponse -> MethodResponse -> Bool
$c/= :: MethodResponse -> MethodResponse -> Bool
== :: MethodResponse -> MethodResponse -> Bool
$c== :: MethodResponse -> MethodResponse -> Bool
Prelude.Eq, ReadPrec [MethodResponse]
ReadPrec MethodResponse
Int -> ReadS MethodResponse
ReadS [MethodResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MethodResponse]
$creadListPrec :: ReadPrec [MethodResponse]
readPrec :: ReadPrec MethodResponse
$creadPrec :: ReadPrec MethodResponse
readList :: ReadS [MethodResponse]
$creadList :: ReadS [MethodResponse]
readsPrec :: Int -> ReadS MethodResponse
$creadsPrec :: Int -> ReadS MethodResponse
Prelude.Read, Int -> MethodResponse -> ShowS
[MethodResponse] -> ShowS
MethodResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MethodResponse] -> ShowS
$cshowList :: [MethodResponse] -> ShowS
show :: MethodResponse -> String
$cshow :: MethodResponse -> String
showsPrec :: Int -> MethodResponse -> ShowS
$cshowsPrec :: Int -> MethodResponse -> ShowS
Prelude.Show, forall x. Rep MethodResponse x -> MethodResponse
forall x. MethodResponse -> Rep MethodResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MethodResponse x -> MethodResponse
$cfrom :: forall x. MethodResponse -> Rep MethodResponse x
Prelude.Generic)

-- |
-- Create a value of 'MethodResponse' 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:
--
-- 'responseModels', 'methodResponse_responseModels' - Specifies the Model resources used for the response\'s content-type.
-- Response models are represented as a key\/value map, with a content-type
-- as the key and a Model name as the value.
--
-- 'responseParameters', 'methodResponse_responseParameters' - A key-value map specifying required or optional response parameters that
-- API Gateway can send back to the caller. A key defines a method response
-- header and the value specifies whether the associated method response
-- header is required or not. The expression of the key must match the
-- pattern @method.response.header.{name}@, where @name@ is a valid and
-- unique header name. API Gateway passes certain integration response data
-- to the method response headers specified here according to the mapping
-- you prescribe in the API\'s IntegrationResponse. The integration
-- response data that can be mapped include an integration response header
-- expressed in @integration.response.header.{name}@, a static value
-- enclosed within a pair of single quotes (e.g., @\'application\/json\'@),
-- or a JSON expression from the back-end response payload in the form of
-- @integration.response.body.{JSON-expression}@, where @JSON-expression@
-- is a valid JSON expression without the @$@ prefix.)
--
-- 'statusCode', 'methodResponse_statusCode' - The method response\'s status code.
newMethodResponse ::
  MethodResponse
newMethodResponse :: MethodResponse
newMethodResponse =
  MethodResponse'
    { $sel:responseModels:MethodResponse' :: Maybe (HashMap Text Text)
responseModels = forall a. Maybe a
Prelude.Nothing,
      $sel:responseParameters:MethodResponse' :: Maybe (HashMap Text Bool)
responseParameters = forall a. Maybe a
Prelude.Nothing,
      $sel:statusCode:MethodResponse' :: Maybe Text
statusCode = forall a. Maybe a
Prelude.Nothing
    }

-- | Specifies the Model resources used for the response\'s content-type.
-- Response models are represented as a key\/value map, with a content-type
-- as the key and a Model name as the value.
methodResponse_responseModels :: Lens.Lens' MethodResponse (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
methodResponse_responseModels :: Lens' MethodResponse (Maybe (HashMap Text Text))
methodResponse_responseModels = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MethodResponse' {Maybe (HashMap Text Text)
responseModels :: Maybe (HashMap Text Text)
$sel:responseModels:MethodResponse' :: MethodResponse -> Maybe (HashMap Text Text)
responseModels} -> Maybe (HashMap Text Text)
responseModels) (\s :: MethodResponse
s@MethodResponse' {} Maybe (HashMap Text Text)
a -> MethodResponse
s {$sel:responseModels:MethodResponse' :: Maybe (HashMap Text Text)
responseModels = Maybe (HashMap Text Text)
a} :: MethodResponse) 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

-- | A key-value map specifying required or optional response parameters that
-- API Gateway can send back to the caller. A key defines a method response
-- header and the value specifies whether the associated method response
-- header is required or not. The expression of the key must match the
-- pattern @method.response.header.{name}@, where @name@ is a valid and
-- unique header name. API Gateway passes certain integration response data
-- to the method response headers specified here according to the mapping
-- you prescribe in the API\'s IntegrationResponse. The integration
-- response data that can be mapped include an integration response header
-- expressed in @integration.response.header.{name}@, a static value
-- enclosed within a pair of single quotes (e.g., @\'application\/json\'@),
-- or a JSON expression from the back-end response payload in the form of
-- @integration.response.body.{JSON-expression}@, where @JSON-expression@
-- is a valid JSON expression without the @$@ prefix.)
methodResponse_responseParameters :: Lens.Lens' MethodResponse (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Bool))
methodResponse_responseParameters :: Lens' MethodResponse (Maybe (HashMap Text Bool))
methodResponse_responseParameters = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MethodResponse' {Maybe (HashMap Text Bool)
responseParameters :: Maybe (HashMap Text Bool)
$sel:responseParameters:MethodResponse' :: MethodResponse -> Maybe (HashMap Text Bool)
responseParameters} -> Maybe (HashMap Text Bool)
responseParameters) (\s :: MethodResponse
s@MethodResponse' {} Maybe (HashMap Text Bool)
a -> MethodResponse
s {$sel:responseParameters:MethodResponse' :: Maybe (HashMap Text Bool)
responseParameters = Maybe (HashMap Text Bool)
a} :: MethodResponse) 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 method response\'s status code.
methodResponse_statusCode :: Lens.Lens' MethodResponse (Prelude.Maybe Prelude.Text)
methodResponse_statusCode :: Lens' MethodResponse (Maybe Text)
methodResponse_statusCode = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MethodResponse' {Maybe Text
statusCode :: Maybe Text
$sel:statusCode:MethodResponse' :: MethodResponse -> Maybe Text
statusCode} -> Maybe Text
statusCode) (\s :: MethodResponse
s@MethodResponse' {} Maybe Text
a -> MethodResponse
s {$sel:statusCode:MethodResponse' :: Maybe Text
statusCode = Maybe Text
a} :: MethodResponse)

instance Data.FromJSON MethodResponse where
  parseJSON :: Value -> Parser MethodResponse
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"MethodResponse"
      ( \Object
x ->
          Maybe (HashMap Text Text)
-> Maybe (HashMap Text Bool) -> Maybe Text -> MethodResponse
MethodResponse'
            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
"responseModels" 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
"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
"statusCode")
      )

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

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