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

import Amazonka.APIGateway.Types.ContentHandlingStrategy
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 an integration response. The status code must map to an
-- existing MethodResponse, and parameters and templates can be used to
-- transform the back-end response.
--
-- /See:/ 'newIntegrationResponse' smart constructor.
data IntegrationResponse = IntegrationResponse'
  { -- | Specifies how to handle response payload content type conversions.
    -- Supported values are @CONVERT_TO_BINARY@ and @CONVERT_TO_TEXT@, with the
    -- following behaviors:
    --
    -- If this property is not defined, the response payload will be passed
    -- through from the integration response to the method response without
    -- modification.
    IntegrationResponse -> Maybe ContentHandlingStrategy
contentHandling :: Prelude.Maybe ContentHandlingStrategy,
    -- | A key-value map specifying response parameters that are passed to the
    -- method response from the back end. The key is a method response header
    -- parameter name and the mapped value is an integration response header
    -- value, a static value enclosed within a pair of single quotes, or a JSON
    -- expression from the integration response body. The mapping key must
    -- match the pattern of @method.response.header.{name}@, where @name@ is a
    -- valid and unique header name. The mapped non-static value must match the
    -- pattern of @integration.response.header.{name}@ or
    -- @integration.response.body.{JSON-expression}@, where @name@ is a valid
    -- and unique response header name and @JSON-expression@ is a valid JSON
    -- expression without the @$@ prefix.
    IntegrationResponse -> Maybe (HashMap Text Text)
responseParameters :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | Specifies the templates used to transform the integration response body.
    -- Response templates are represented as a key\/value map, with a
    -- content-type as the key and a template as the value.
    IntegrationResponse -> Maybe (HashMap Text Text)
responseTemplates :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | Specifies the regular expression (regex) pattern used to choose an
    -- integration response based on the response from the back end. For
    -- example, if the success response returns nothing and the error response
    -- returns some string, you could use the @.+@ regex to match error
    -- response. However, make sure that the error response does not contain
    -- any newline (@\\n@) character in such cases. If the back end is an AWS
    -- Lambda function, the AWS Lambda function error header is matched. For
    -- all other HTTP and AWS back ends, the HTTP status code is matched.
    IntegrationResponse -> Maybe Text
selectionPattern :: Prelude.Maybe Prelude.Text,
    -- | Specifies the status code that is used to map the integration response
    -- to an existing MethodResponse.
    IntegrationResponse -> Maybe Text
statusCode :: Prelude.Maybe Prelude.Text
  }
  deriving (IntegrationResponse -> IntegrationResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IntegrationResponse -> IntegrationResponse -> Bool
$c/= :: IntegrationResponse -> IntegrationResponse -> Bool
== :: IntegrationResponse -> IntegrationResponse -> Bool
$c== :: IntegrationResponse -> IntegrationResponse -> Bool
Prelude.Eq, ReadPrec [IntegrationResponse]
ReadPrec IntegrationResponse
Int -> ReadS IntegrationResponse
ReadS [IntegrationResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [IntegrationResponse]
$creadListPrec :: ReadPrec [IntegrationResponse]
readPrec :: ReadPrec IntegrationResponse
$creadPrec :: ReadPrec IntegrationResponse
readList :: ReadS [IntegrationResponse]
$creadList :: ReadS [IntegrationResponse]
readsPrec :: Int -> ReadS IntegrationResponse
$creadsPrec :: Int -> ReadS IntegrationResponse
Prelude.Read, Int -> IntegrationResponse -> ShowS
[IntegrationResponse] -> ShowS
IntegrationResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IntegrationResponse] -> ShowS
$cshowList :: [IntegrationResponse] -> ShowS
show :: IntegrationResponse -> String
$cshow :: IntegrationResponse -> String
showsPrec :: Int -> IntegrationResponse -> ShowS
$cshowsPrec :: Int -> IntegrationResponse -> ShowS
Prelude.Show, forall x. Rep IntegrationResponse x -> IntegrationResponse
forall x. IntegrationResponse -> Rep IntegrationResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep IntegrationResponse x -> IntegrationResponse
$cfrom :: forall x. IntegrationResponse -> Rep IntegrationResponse x
Prelude.Generic)

-- |
-- Create a value of 'IntegrationResponse' 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:
--
-- 'contentHandling', 'integrationResponse_contentHandling' - Specifies how to handle response payload content type conversions.
-- Supported values are @CONVERT_TO_BINARY@ and @CONVERT_TO_TEXT@, with the
-- following behaviors:
--
-- If this property is not defined, the response payload will be passed
-- through from the integration response to the method response without
-- modification.
--
-- 'responseParameters', 'integrationResponse_responseParameters' - A key-value map specifying response parameters that are passed to the
-- method response from the back end. The key is a method response header
-- parameter name and the mapped value is an integration response header
-- value, a static value enclosed within a pair of single quotes, or a JSON
-- expression from the integration response body. The mapping key must
-- match the pattern of @method.response.header.{name}@, where @name@ is a
-- valid and unique header name. The mapped non-static value must match the
-- pattern of @integration.response.header.{name}@ or
-- @integration.response.body.{JSON-expression}@, where @name@ is a valid
-- and unique response header name and @JSON-expression@ is a valid JSON
-- expression without the @$@ prefix.
--
-- 'responseTemplates', 'integrationResponse_responseTemplates' - Specifies the templates used to transform the integration response body.
-- Response templates are represented as a key\/value map, with a
-- content-type as the key and a template as the value.
--
-- 'selectionPattern', 'integrationResponse_selectionPattern' - Specifies the regular expression (regex) pattern used to choose an
-- integration response based on the response from the back end. For
-- example, if the success response returns nothing and the error response
-- returns some string, you could use the @.+@ regex to match error
-- response. However, make sure that the error response does not contain
-- any newline (@\\n@) character in such cases. If the back end is an AWS
-- Lambda function, the AWS Lambda function error header is matched. For
-- all other HTTP and AWS back ends, the HTTP status code is matched.
--
-- 'statusCode', 'integrationResponse_statusCode' - Specifies the status code that is used to map the integration response
-- to an existing MethodResponse.
newIntegrationResponse ::
  IntegrationResponse
newIntegrationResponse :: IntegrationResponse
newIntegrationResponse =
  IntegrationResponse'
    { $sel:contentHandling:IntegrationResponse' :: Maybe ContentHandlingStrategy
contentHandling =
        forall a. Maybe a
Prelude.Nothing,
      $sel:responseParameters:IntegrationResponse' :: Maybe (HashMap Text Text)
responseParameters = forall a. Maybe a
Prelude.Nothing,
      $sel:responseTemplates:IntegrationResponse' :: Maybe (HashMap Text Text)
responseTemplates = forall a. Maybe a
Prelude.Nothing,
      $sel:selectionPattern:IntegrationResponse' :: Maybe Text
selectionPattern = forall a. Maybe a
Prelude.Nothing,
      $sel:statusCode:IntegrationResponse' :: Maybe Text
statusCode = forall a. Maybe a
Prelude.Nothing
    }

-- | Specifies how to handle response payload content type conversions.
-- Supported values are @CONVERT_TO_BINARY@ and @CONVERT_TO_TEXT@, with the
-- following behaviors:
--
-- If this property is not defined, the response payload will be passed
-- through from the integration response to the method response without
-- modification.
integrationResponse_contentHandling :: Lens.Lens' IntegrationResponse (Prelude.Maybe ContentHandlingStrategy)
integrationResponse_contentHandling :: Lens' IntegrationResponse (Maybe ContentHandlingStrategy)
integrationResponse_contentHandling = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IntegrationResponse' {Maybe ContentHandlingStrategy
contentHandling :: Maybe ContentHandlingStrategy
$sel:contentHandling:IntegrationResponse' :: IntegrationResponse -> Maybe ContentHandlingStrategy
contentHandling} -> Maybe ContentHandlingStrategy
contentHandling) (\s :: IntegrationResponse
s@IntegrationResponse' {} Maybe ContentHandlingStrategy
a -> IntegrationResponse
s {$sel:contentHandling:IntegrationResponse' :: Maybe ContentHandlingStrategy
contentHandling = Maybe ContentHandlingStrategy
a} :: IntegrationResponse)

-- | A key-value map specifying response parameters that are passed to the
-- method response from the back end. The key is a method response header
-- parameter name and the mapped value is an integration response header
-- value, a static value enclosed within a pair of single quotes, or a JSON
-- expression from the integration response body. The mapping key must
-- match the pattern of @method.response.header.{name}@, where @name@ is a
-- valid and unique header name. The mapped non-static value must match the
-- pattern of @integration.response.header.{name}@ or
-- @integration.response.body.{JSON-expression}@, where @name@ is a valid
-- and unique response header name and @JSON-expression@ is a valid JSON
-- expression without the @$@ prefix.
integrationResponse_responseParameters :: Lens.Lens' IntegrationResponse (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
integrationResponse_responseParameters :: Lens' IntegrationResponse (Maybe (HashMap Text Text))
integrationResponse_responseParameters = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IntegrationResponse' {Maybe (HashMap Text Text)
responseParameters :: Maybe (HashMap Text Text)
$sel:responseParameters:IntegrationResponse' :: IntegrationResponse -> Maybe (HashMap Text Text)
responseParameters} -> Maybe (HashMap Text Text)
responseParameters) (\s :: IntegrationResponse
s@IntegrationResponse' {} Maybe (HashMap Text Text)
a -> IntegrationResponse
s {$sel:responseParameters:IntegrationResponse' :: Maybe (HashMap Text Text)
responseParameters = Maybe (HashMap Text Text)
a} :: IntegrationResponse) 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

-- | Specifies the templates used to transform the integration response body.
-- Response templates are represented as a key\/value map, with a
-- content-type as the key and a template as the value.
integrationResponse_responseTemplates :: Lens.Lens' IntegrationResponse (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
integrationResponse_responseTemplates :: Lens' IntegrationResponse (Maybe (HashMap Text Text))
integrationResponse_responseTemplates = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IntegrationResponse' {Maybe (HashMap Text Text)
responseTemplates :: Maybe (HashMap Text Text)
$sel:responseTemplates:IntegrationResponse' :: IntegrationResponse -> Maybe (HashMap Text Text)
responseTemplates} -> Maybe (HashMap Text Text)
responseTemplates) (\s :: IntegrationResponse
s@IntegrationResponse' {} Maybe (HashMap Text Text)
a -> IntegrationResponse
s {$sel:responseTemplates:IntegrationResponse' :: Maybe (HashMap Text Text)
responseTemplates = Maybe (HashMap Text Text)
a} :: IntegrationResponse) 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

-- | Specifies the regular expression (regex) pattern used to choose an
-- integration response based on the response from the back end. For
-- example, if the success response returns nothing and the error response
-- returns some string, you could use the @.+@ regex to match error
-- response. However, make sure that the error response does not contain
-- any newline (@\\n@) character in such cases. If the back end is an AWS
-- Lambda function, the AWS Lambda function error header is matched. For
-- all other HTTP and AWS back ends, the HTTP status code is matched.
integrationResponse_selectionPattern :: Lens.Lens' IntegrationResponse (Prelude.Maybe Prelude.Text)
integrationResponse_selectionPattern :: Lens' IntegrationResponse (Maybe Text)
integrationResponse_selectionPattern = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IntegrationResponse' {Maybe Text
selectionPattern :: Maybe Text
$sel:selectionPattern:IntegrationResponse' :: IntegrationResponse -> Maybe Text
selectionPattern} -> Maybe Text
selectionPattern) (\s :: IntegrationResponse
s@IntegrationResponse' {} Maybe Text
a -> IntegrationResponse
s {$sel:selectionPattern:IntegrationResponse' :: Maybe Text
selectionPattern = Maybe Text
a} :: IntegrationResponse)

-- | Specifies the status code that is used to map the integration response
-- to an existing MethodResponse.
integrationResponse_statusCode :: Lens.Lens' IntegrationResponse (Prelude.Maybe Prelude.Text)
integrationResponse_statusCode :: Lens' IntegrationResponse (Maybe Text)
integrationResponse_statusCode = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IntegrationResponse' {Maybe Text
statusCode :: Maybe Text
$sel:statusCode:IntegrationResponse' :: IntegrationResponse -> Maybe Text
statusCode} -> Maybe Text
statusCode) (\s :: IntegrationResponse
s@IntegrationResponse' {} Maybe Text
a -> IntegrationResponse
s {$sel:statusCode:IntegrationResponse' :: Maybe Text
statusCode = Maybe Text
a} :: IntegrationResponse)

instance Data.FromJSON IntegrationResponse where
  parseJSON :: Value -> Parser IntegrationResponse
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"IntegrationResponse"
      ( \Object
x ->
          Maybe ContentHandlingStrategy
-> Maybe (HashMap Text Text)
-> Maybe (HashMap Text Text)
-> Maybe Text
-> Maybe Text
-> IntegrationResponse
IntegrationResponse'
            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
"contentHandling")
            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
"selectionPattern")
            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 IntegrationResponse where
  hashWithSalt :: Int -> IntegrationResponse -> Int
hashWithSalt Int
_salt IntegrationResponse' {Maybe Text
Maybe (HashMap Text Text)
Maybe ContentHandlingStrategy
statusCode :: Maybe Text
selectionPattern :: Maybe Text
responseTemplates :: Maybe (HashMap Text Text)
responseParameters :: Maybe (HashMap Text Text)
contentHandling :: Maybe ContentHandlingStrategy
$sel:statusCode:IntegrationResponse' :: IntegrationResponse -> Maybe Text
$sel:selectionPattern:IntegrationResponse' :: IntegrationResponse -> Maybe Text
$sel:responseTemplates:IntegrationResponse' :: IntegrationResponse -> Maybe (HashMap Text Text)
$sel:responseParameters:IntegrationResponse' :: IntegrationResponse -> Maybe (HashMap Text Text)
$sel:contentHandling:IntegrationResponse' :: IntegrationResponse -> Maybe ContentHandlingStrategy
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ContentHandlingStrategy
contentHandling
      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 Text
selectionPattern
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
statusCode

instance Prelude.NFData IntegrationResponse where
  rnf :: IntegrationResponse -> ()
rnf IntegrationResponse' {Maybe Text
Maybe (HashMap Text Text)
Maybe ContentHandlingStrategy
statusCode :: Maybe Text
selectionPattern :: Maybe Text
responseTemplates :: Maybe (HashMap Text Text)
responseParameters :: Maybe (HashMap Text Text)
contentHandling :: Maybe ContentHandlingStrategy
$sel:statusCode:IntegrationResponse' :: IntegrationResponse -> Maybe Text
$sel:selectionPattern:IntegrationResponse' :: IntegrationResponse -> Maybe Text
$sel:responseTemplates:IntegrationResponse' :: IntegrationResponse -> Maybe (HashMap Text Text)
$sel:responseParameters:IntegrationResponse' :: IntegrationResponse -> Maybe (HashMap Text Text)
$sel:contentHandling:IntegrationResponse' :: IntegrationResponse -> Maybe ContentHandlingStrategy
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe ContentHandlingStrategy
contentHandling
      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 Text
selectionPattern
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
statusCode