{-# 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.BlockAction
-- 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.BlockAction 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.CustomResponse

-- | Specifies that WAF should block the request and optionally defines
-- additional custom handling for the response to the web request.
--
-- This is used in the context of other settings, for example to specify
-- values for RuleAction and web ACL DefaultAction.
--
-- /See:/ 'newBlockAction' smart constructor.
data BlockAction = BlockAction'
  { -- | Defines a custom response for the web request.
    --
    -- For information about customizing web requests and responses, see
    -- <https://docs.aws.amazon.com/waf/latest/developerguide/waf-custom-request-response.html Customizing web requests and responses in WAF>
    -- in the
    -- <https://docs.aws.amazon.com/waf/latest/developerguide/waf-chapter.html WAF Developer Guide>.
    BlockAction -> Maybe CustomResponse
customResponse :: Prelude.Maybe CustomResponse
  }
  deriving (BlockAction -> BlockAction -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BlockAction -> BlockAction -> Bool
$c/= :: BlockAction -> BlockAction -> Bool
== :: BlockAction -> BlockAction -> Bool
$c== :: BlockAction -> BlockAction -> Bool
Prelude.Eq, ReadPrec [BlockAction]
ReadPrec BlockAction
Int -> ReadS BlockAction
ReadS [BlockAction]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BlockAction]
$creadListPrec :: ReadPrec [BlockAction]
readPrec :: ReadPrec BlockAction
$creadPrec :: ReadPrec BlockAction
readList :: ReadS [BlockAction]
$creadList :: ReadS [BlockAction]
readsPrec :: Int -> ReadS BlockAction
$creadsPrec :: Int -> ReadS BlockAction
Prelude.Read, Int -> BlockAction -> ShowS
[BlockAction] -> ShowS
BlockAction -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BlockAction] -> ShowS
$cshowList :: [BlockAction] -> ShowS
show :: BlockAction -> String
$cshow :: BlockAction -> String
showsPrec :: Int -> BlockAction -> ShowS
$cshowsPrec :: Int -> BlockAction -> ShowS
Prelude.Show, forall x. Rep BlockAction x -> BlockAction
forall x. BlockAction -> Rep BlockAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BlockAction x -> BlockAction
$cfrom :: forall x. BlockAction -> Rep BlockAction x
Prelude.Generic)

-- |
-- Create a value of 'BlockAction' 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:
--
-- 'customResponse', 'blockAction_customResponse' - Defines a custom response for the web request.
--
-- For information about customizing web requests and responses, see
-- <https://docs.aws.amazon.com/waf/latest/developerguide/waf-custom-request-response.html Customizing web requests and responses in WAF>
-- in the
-- <https://docs.aws.amazon.com/waf/latest/developerguide/waf-chapter.html WAF Developer Guide>.
newBlockAction ::
  BlockAction
newBlockAction :: BlockAction
newBlockAction =
  BlockAction' {$sel:customResponse:BlockAction' :: Maybe CustomResponse
customResponse = forall a. Maybe a
Prelude.Nothing}

-- | Defines a custom response for the web request.
--
-- For information about customizing web requests and responses, see
-- <https://docs.aws.amazon.com/waf/latest/developerguide/waf-custom-request-response.html Customizing web requests and responses in WAF>
-- in the
-- <https://docs.aws.amazon.com/waf/latest/developerguide/waf-chapter.html WAF Developer Guide>.
blockAction_customResponse :: Lens.Lens' BlockAction (Prelude.Maybe CustomResponse)
blockAction_customResponse :: Lens' BlockAction (Maybe CustomResponse)
blockAction_customResponse = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BlockAction' {Maybe CustomResponse
customResponse :: Maybe CustomResponse
$sel:customResponse:BlockAction' :: BlockAction -> Maybe CustomResponse
customResponse} -> Maybe CustomResponse
customResponse) (\s :: BlockAction
s@BlockAction' {} Maybe CustomResponse
a -> BlockAction
s {$sel:customResponse:BlockAction' :: Maybe CustomResponse
customResponse = Maybe CustomResponse
a} :: BlockAction)

instance Data.FromJSON BlockAction where
  parseJSON :: Value -> Parser BlockAction
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"BlockAction"
      ( \Object
x ->
          Maybe CustomResponse -> BlockAction
BlockAction'
            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
"CustomResponse")
      )

instance Prelude.Hashable BlockAction where
  hashWithSalt :: Int -> BlockAction -> Int
hashWithSalt Int
_salt BlockAction' {Maybe CustomResponse
customResponse :: Maybe CustomResponse
$sel:customResponse:BlockAction' :: BlockAction -> Maybe CustomResponse
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe CustomResponse
customResponse

instance Prelude.NFData BlockAction where
  rnf :: BlockAction -> ()
rnf BlockAction' {Maybe CustomResponse
customResponse :: Maybe CustomResponse
$sel:customResponse:BlockAction' :: BlockAction -> Maybe CustomResponse
..} = forall a. NFData a => a -> ()
Prelude.rnf Maybe CustomResponse
customResponse

instance Data.ToJSON BlockAction where
  toJSON :: BlockAction -> Value
toJSON BlockAction' {Maybe CustomResponse
customResponse :: Maybe CustomResponse
$sel:customResponse:BlockAction' :: BlockAction -> Maybe CustomResponse
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"CustomResponse" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe CustomResponse
customResponse
          ]
      )