{-# 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.WAFV2.Types.CustomResponseBody
-- 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.WAFV2.Types.CustomResponseBody 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
import Amazonka.WAFV2.Types.ResponseContentType

-- | The response body to use in a custom response to a web request. This is
-- referenced by key from CustomResponse @CustomResponseBodyKey@.
--
-- /See:/ 'newCustomResponseBody' smart constructor.
data CustomResponseBody = CustomResponseBody'
  { -- | The type of content in the payload that you are defining in the
    -- @Content@ string.
    CustomResponseBody -> ResponseContentType
contentType :: ResponseContentType,
    -- | The payload of the custom response.
    --
    -- You can use JSON escape strings in JSON content. To do this, you must
    -- specify JSON content in the @ContentType@ setting.
    --
    -- For information about the limits on count and size for custom request
    -- and response settings, see
    -- <https://docs.aws.amazon.com/waf/latest/developerguide/limits.html WAF quotas>
    -- in the
    -- <https://docs.aws.amazon.com/waf/latest/developerguide/waf-chapter.html WAF Developer Guide>.
    CustomResponseBody -> Text
content :: Prelude.Text
  }
  deriving (CustomResponseBody -> CustomResponseBody -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CustomResponseBody -> CustomResponseBody -> Bool
$c/= :: CustomResponseBody -> CustomResponseBody -> Bool
== :: CustomResponseBody -> CustomResponseBody -> Bool
$c== :: CustomResponseBody -> CustomResponseBody -> Bool
Prelude.Eq, ReadPrec [CustomResponseBody]
ReadPrec CustomResponseBody
Int -> ReadS CustomResponseBody
ReadS [CustomResponseBody]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CustomResponseBody]
$creadListPrec :: ReadPrec [CustomResponseBody]
readPrec :: ReadPrec CustomResponseBody
$creadPrec :: ReadPrec CustomResponseBody
readList :: ReadS [CustomResponseBody]
$creadList :: ReadS [CustomResponseBody]
readsPrec :: Int -> ReadS CustomResponseBody
$creadsPrec :: Int -> ReadS CustomResponseBody
Prelude.Read, Int -> CustomResponseBody -> ShowS
[CustomResponseBody] -> ShowS
CustomResponseBody -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CustomResponseBody] -> ShowS
$cshowList :: [CustomResponseBody] -> ShowS
show :: CustomResponseBody -> String
$cshow :: CustomResponseBody -> String
showsPrec :: Int -> CustomResponseBody -> ShowS
$cshowsPrec :: Int -> CustomResponseBody -> ShowS
Prelude.Show, forall x. Rep CustomResponseBody x -> CustomResponseBody
forall x. CustomResponseBody -> Rep CustomResponseBody x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CustomResponseBody x -> CustomResponseBody
$cfrom :: forall x. CustomResponseBody -> Rep CustomResponseBody x
Prelude.Generic)

-- |
-- Create a value of 'CustomResponseBody' 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:
--
-- 'contentType', 'customResponseBody_contentType' - The type of content in the payload that you are defining in the
-- @Content@ string.
--
-- 'content', 'customResponseBody_content' - The payload of the custom response.
--
-- You can use JSON escape strings in JSON content. To do this, you must
-- specify JSON content in the @ContentType@ setting.
--
-- For information about the limits on count and size for custom request
-- and response settings, see
-- <https://docs.aws.amazon.com/waf/latest/developerguide/limits.html WAF quotas>
-- in the
-- <https://docs.aws.amazon.com/waf/latest/developerguide/waf-chapter.html WAF Developer Guide>.
newCustomResponseBody ::
  -- | 'contentType'
  ResponseContentType ->
  -- | 'content'
  Prelude.Text ->
  CustomResponseBody
newCustomResponseBody :: ResponseContentType -> Text -> CustomResponseBody
newCustomResponseBody ResponseContentType
pContentType_ Text
pContent_ =
  CustomResponseBody'
    { $sel:contentType:CustomResponseBody' :: ResponseContentType
contentType = ResponseContentType
pContentType_,
      $sel:content:CustomResponseBody' :: Text
content = Text
pContent_
    }

-- | The type of content in the payload that you are defining in the
-- @Content@ string.
customResponseBody_contentType :: Lens.Lens' CustomResponseBody ResponseContentType
customResponseBody_contentType :: Lens' CustomResponseBody ResponseContentType
customResponseBody_contentType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomResponseBody' {ResponseContentType
contentType :: ResponseContentType
$sel:contentType:CustomResponseBody' :: CustomResponseBody -> ResponseContentType
contentType} -> ResponseContentType
contentType) (\s :: CustomResponseBody
s@CustomResponseBody' {} ResponseContentType
a -> CustomResponseBody
s {$sel:contentType:CustomResponseBody' :: ResponseContentType
contentType = ResponseContentType
a} :: CustomResponseBody)

-- | The payload of the custom response.
--
-- You can use JSON escape strings in JSON content. To do this, you must
-- specify JSON content in the @ContentType@ setting.
--
-- For information about the limits on count and size for custom request
-- and response settings, see
-- <https://docs.aws.amazon.com/waf/latest/developerguide/limits.html WAF quotas>
-- in the
-- <https://docs.aws.amazon.com/waf/latest/developerguide/waf-chapter.html WAF Developer Guide>.
customResponseBody_content :: Lens.Lens' CustomResponseBody Prelude.Text
customResponseBody_content :: Lens' CustomResponseBody Text
customResponseBody_content = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomResponseBody' {Text
content :: Text
$sel:content:CustomResponseBody' :: CustomResponseBody -> Text
content} -> Text
content) (\s :: CustomResponseBody
s@CustomResponseBody' {} Text
a -> CustomResponseBody
s {$sel:content:CustomResponseBody' :: Text
content = Text
a} :: CustomResponseBody)

instance Data.FromJSON CustomResponseBody where
  parseJSON :: Value -> Parser CustomResponseBody
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"CustomResponseBody"
      ( \Object
x ->
          ResponseContentType -> Text -> CustomResponseBody
CustomResponseBody'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"ContentType")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Content")
      )

instance Prelude.Hashable CustomResponseBody where
  hashWithSalt :: Int -> CustomResponseBody -> Int
hashWithSalt Int
_salt CustomResponseBody' {Text
ResponseContentType
content :: Text
contentType :: ResponseContentType
$sel:content:CustomResponseBody' :: CustomResponseBody -> Text
$sel:contentType:CustomResponseBody' :: CustomResponseBody -> ResponseContentType
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ResponseContentType
contentType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
content

instance Prelude.NFData CustomResponseBody where
  rnf :: CustomResponseBody -> ()
rnf CustomResponseBody' {Text
ResponseContentType
content :: Text
contentType :: ResponseContentType
$sel:content:CustomResponseBody' :: CustomResponseBody -> Text
$sel:contentType:CustomResponseBody' :: CustomResponseBody -> ResponseContentType
..} =
    forall a. NFData a => a -> ()
Prelude.rnf ResponseContentType
contentType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
content

instance Data.ToJSON CustomResponseBody where
  toJSON :: CustomResponseBody -> Value
toJSON CustomResponseBody' {Text
ResponseContentType
content :: Text
contentType :: ResponseContentType
$sel:content:CustomResponseBody' :: CustomResponseBody -> Text
$sel:contentType:CustomResponseBody' :: CustomResponseBody -> ResponseContentType
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"ContentType" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ResponseContentType
contentType),
            forall a. a -> Maybe a
Prelude.Just (Key
"Content" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
content)
          ]
      )