{-# 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.Shield.Types.ResponseAction
-- 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.Shield.Types.ResponseAction 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.Shield.Types.BlockAction
import Amazonka.Shield.Types.CountAction

-- | Specifies the action setting that Shield Advanced should use in the WAF
-- rules that it creates on behalf of the protected resource in response to
-- DDoS attacks. You specify this as part of the configuration for the
-- automatic application layer DDoS mitigation feature, when you enable or
-- update automatic mitigation. Shield Advanced creates the WAF rules in a
-- Shield Advanced-managed rule group, inside the web ACL that you have
-- associated with the resource.
--
-- /See:/ 'newResponseAction' smart constructor.
data ResponseAction = ResponseAction'
  { -- | Specifies that Shield Advanced should configure its WAF rules with the
    -- WAF @Block@ action.
    --
    -- You must specify exactly one action, either @Block@ or @Count@.
    ResponseAction -> Maybe BlockAction
block :: Prelude.Maybe BlockAction,
    -- | Specifies that Shield Advanced should configure its WAF rules with the
    -- WAF @Count@ action.
    --
    -- You must specify exactly one action, either @Block@ or @Count@.
    ResponseAction -> Maybe CountAction
count :: Prelude.Maybe CountAction
  }
  deriving (ResponseAction -> ResponseAction -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResponseAction -> ResponseAction -> Bool
$c/= :: ResponseAction -> ResponseAction -> Bool
== :: ResponseAction -> ResponseAction -> Bool
$c== :: ResponseAction -> ResponseAction -> Bool
Prelude.Eq, ReadPrec [ResponseAction]
ReadPrec ResponseAction
Int -> ReadS ResponseAction
ReadS [ResponseAction]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ResponseAction]
$creadListPrec :: ReadPrec [ResponseAction]
readPrec :: ReadPrec ResponseAction
$creadPrec :: ReadPrec ResponseAction
readList :: ReadS [ResponseAction]
$creadList :: ReadS [ResponseAction]
readsPrec :: Int -> ReadS ResponseAction
$creadsPrec :: Int -> ReadS ResponseAction
Prelude.Read, Int -> ResponseAction -> ShowS
[ResponseAction] -> ShowS
ResponseAction -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResponseAction] -> ShowS
$cshowList :: [ResponseAction] -> ShowS
show :: ResponseAction -> String
$cshow :: ResponseAction -> String
showsPrec :: Int -> ResponseAction -> ShowS
$cshowsPrec :: Int -> ResponseAction -> ShowS
Prelude.Show, forall x. Rep ResponseAction x -> ResponseAction
forall x. ResponseAction -> Rep ResponseAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ResponseAction x -> ResponseAction
$cfrom :: forall x. ResponseAction -> Rep ResponseAction x
Prelude.Generic)

-- |
-- Create a value of 'ResponseAction' 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:
--
-- 'block', 'responseAction_block' - Specifies that Shield Advanced should configure its WAF rules with the
-- WAF @Block@ action.
--
-- You must specify exactly one action, either @Block@ or @Count@.
--
-- 'count', 'responseAction_count' - Specifies that Shield Advanced should configure its WAF rules with the
-- WAF @Count@ action.
--
-- You must specify exactly one action, either @Block@ or @Count@.
newResponseAction ::
  ResponseAction
newResponseAction :: ResponseAction
newResponseAction =
  ResponseAction'
    { $sel:block:ResponseAction' :: Maybe BlockAction
block = forall a. Maybe a
Prelude.Nothing,
      $sel:count:ResponseAction' :: Maybe CountAction
count = forall a. Maybe a
Prelude.Nothing
    }

-- | Specifies that Shield Advanced should configure its WAF rules with the
-- WAF @Block@ action.
--
-- You must specify exactly one action, either @Block@ or @Count@.
responseAction_block :: Lens.Lens' ResponseAction (Prelude.Maybe BlockAction)
responseAction_block :: Lens' ResponseAction (Maybe BlockAction)
responseAction_block = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResponseAction' {Maybe BlockAction
block :: Maybe BlockAction
$sel:block:ResponseAction' :: ResponseAction -> Maybe BlockAction
block} -> Maybe BlockAction
block) (\s :: ResponseAction
s@ResponseAction' {} Maybe BlockAction
a -> ResponseAction
s {$sel:block:ResponseAction' :: Maybe BlockAction
block = Maybe BlockAction
a} :: ResponseAction)

-- | Specifies that Shield Advanced should configure its WAF rules with the
-- WAF @Count@ action.
--
-- You must specify exactly one action, either @Block@ or @Count@.
responseAction_count :: Lens.Lens' ResponseAction (Prelude.Maybe CountAction)
responseAction_count :: Lens' ResponseAction (Maybe CountAction)
responseAction_count = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ResponseAction' {Maybe CountAction
count :: Maybe CountAction
$sel:count:ResponseAction' :: ResponseAction -> Maybe CountAction
count} -> Maybe CountAction
count) (\s :: ResponseAction
s@ResponseAction' {} Maybe CountAction
a -> ResponseAction
s {$sel:count:ResponseAction' :: Maybe CountAction
count = Maybe CountAction
a} :: ResponseAction)

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

instance Prelude.Hashable ResponseAction where
  hashWithSalt :: Int -> ResponseAction -> Int
hashWithSalt Int
_salt ResponseAction' {Maybe BlockAction
Maybe CountAction
count :: Maybe CountAction
block :: Maybe BlockAction
$sel:count:ResponseAction' :: ResponseAction -> Maybe CountAction
$sel:block:ResponseAction' :: ResponseAction -> Maybe BlockAction
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe BlockAction
block
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe CountAction
count

instance Prelude.NFData ResponseAction where
  rnf :: ResponseAction -> ()
rnf ResponseAction' {Maybe BlockAction
Maybe CountAction
count :: Maybe CountAction
block :: Maybe BlockAction
$sel:count:ResponseAction' :: ResponseAction -> Maybe CountAction
$sel:block:ResponseAction' :: ResponseAction -> Maybe BlockAction
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe BlockAction
block seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe CountAction
count

instance Data.ToJSON ResponseAction where
  toJSON :: ResponseAction -> Value
toJSON ResponseAction' {Maybe BlockAction
Maybe CountAction
count :: Maybe CountAction
block :: Maybe BlockAction
$sel:count:ResponseAction' :: ResponseAction -> Maybe CountAction
$sel:block:ResponseAction' :: ResponseAction -> Maybe BlockAction
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Block" 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 BlockAction
block,
            (Key
"Count" 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 CountAction
count
          ]
      )