{-# 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.DefaultAction
-- 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.DefaultAction 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.AllowAction
import Amazonka.WAFV2.Types.BlockAction

-- | In a WebACL, this is the action that you want WAF to perform when a web
-- request doesn\'t match any of the rules in the @WebACL@. The default
-- action must be a terminating action.
--
-- /See:/ 'newDefaultAction' smart constructor.
data DefaultAction = DefaultAction'
  { -- | Specifies that WAF should allow requests by default.
    DefaultAction -> Maybe AllowAction
allow :: Prelude.Maybe AllowAction,
    -- | Specifies that WAF should block requests by default.
    DefaultAction -> Maybe BlockAction
block :: Prelude.Maybe BlockAction
  }
  deriving (DefaultAction -> DefaultAction -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DefaultAction -> DefaultAction -> Bool
$c/= :: DefaultAction -> DefaultAction -> Bool
== :: DefaultAction -> DefaultAction -> Bool
$c== :: DefaultAction -> DefaultAction -> Bool
Prelude.Eq, ReadPrec [DefaultAction]
ReadPrec DefaultAction
Int -> ReadS DefaultAction
ReadS [DefaultAction]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DefaultAction]
$creadListPrec :: ReadPrec [DefaultAction]
readPrec :: ReadPrec DefaultAction
$creadPrec :: ReadPrec DefaultAction
readList :: ReadS [DefaultAction]
$creadList :: ReadS [DefaultAction]
readsPrec :: Int -> ReadS DefaultAction
$creadsPrec :: Int -> ReadS DefaultAction
Prelude.Read, Int -> DefaultAction -> ShowS
[DefaultAction] -> ShowS
DefaultAction -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DefaultAction] -> ShowS
$cshowList :: [DefaultAction] -> ShowS
show :: DefaultAction -> String
$cshow :: DefaultAction -> String
showsPrec :: Int -> DefaultAction -> ShowS
$cshowsPrec :: Int -> DefaultAction -> ShowS
Prelude.Show, forall x. Rep DefaultAction x -> DefaultAction
forall x. DefaultAction -> Rep DefaultAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DefaultAction x -> DefaultAction
$cfrom :: forall x. DefaultAction -> Rep DefaultAction x
Prelude.Generic)

-- |
-- Create a value of 'DefaultAction' 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:
--
-- 'allow', 'defaultAction_allow' - Specifies that WAF should allow requests by default.
--
-- 'block', 'defaultAction_block' - Specifies that WAF should block requests by default.
newDefaultAction ::
  DefaultAction
newDefaultAction :: DefaultAction
newDefaultAction =
  DefaultAction'
    { $sel:allow:DefaultAction' :: Maybe AllowAction
allow = forall a. Maybe a
Prelude.Nothing,
      $sel:block:DefaultAction' :: Maybe BlockAction
block = forall a. Maybe a
Prelude.Nothing
    }

-- | Specifies that WAF should allow requests by default.
defaultAction_allow :: Lens.Lens' DefaultAction (Prelude.Maybe AllowAction)
defaultAction_allow :: Lens' DefaultAction (Maybe AllowAction)
defaultAction_allow = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DefaultAction' {Maybe AllowAction
allow :: Maybe AllowAction
$sel:allow:DefaultAction' :: DefaultAction -> Maybe AllowAction
allow} -> Maybe AllowAction
allow) (\s :: DefaultAction
s@DefaultAction' {} Maybe AllowAction
a -> DefaultAction
s {$sel:allow:DefaultAction' :: Maybe AllowAction
allow = Maybe AllowAction
a} :: DefaultAction)

-- | Specifies that WAF should block requests by default.
defaultAction_block :: Lens.Lens' DefaultAction (Prelude.Maybe BlockAction)
defaultAction_block :: Lens' DefaultAction (Maybe BlockAction)
defaultAction_block = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DefaultAction' {Maybe BlockAction
block :: Maybe BlockAction
$sel:block:DefaultAction' :: DefaultAction -> Maybe BlockAction
block} -> Maybe BlockAction
block) (\s :: DefaultAction
s@DefaultAction' {} Maybe BlockAction
a -> DefaultAction
s {$sel:block:DefaultAction' :: Maybe BlockAction
block = Maybe BlockAction
a} :: DefaultAction)

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

instance Prelude.Hashable DefaultAction where
  hashWithSalt :: Int -> DefaultAction -> Int
hashWithSalt Int
_salt DefaultAction' {Maybe AllowAction
Maybe BlockAction
block :: Maybe BlockAction
allow :: Maybe AllowAction
$sel:block:DefaultAction' :: DefaultAction -> Maybe BlockAction
$sel:allow:DefaultAction' :: DefaultAction -> Maybe AllowAction
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe AllowAction
allow
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe BlockAction
block

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

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