{-# 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.ActionCondition
-- 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.ActionCondition 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.ActionValue

-- | A single action condition for a Condition in a logging filter.
--
-- /See:/ 'newActionCondition' smart constructor.
data ActionCondition = ActionCondition'
  { -- | The action setting that a log record must contain in order to meet the
    -- condition. This is the action that WAF applied to the web request.
    --
    -- For rule groups, this is either the configured rule action setting, or
    -- if you\'ve applied a rule action override to the rule, it\'s the
    -- override action. The value @EXCLUDED_AS_COUNT@ matches on excluded rules
    -- and also on rules that have a rule action override of Count.
    ActionCondition -> ActionValue
action :: ActionValue
  }
  deriving (ActionCondition -> ActionCondition -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ActionCondition -> ActionCondition -> Bool
$c/= :: ActionCondition -> ActionCondition -> Bool
== :: ActionCondition -> ActionCondition -> Bool
$c== :: ActionCondition -> ActionCondition -> Bool
Prelude.Eq, ReadPrec [ActionCondition]
ReadPrec ActionCondition
Int -> ReadS ActionCondition
ReadS [ActionCondition]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ActionCondition]
$creadListPrec :: ReadPrec [ActionCondition]
readPrec :: ReadPrec ActionCondition
$creadPrec :: ReadPrec ActionCondition
readList :: ReadS [ActionCondition]
$creadList :: ReadS [ActionCondition]
readsPrec :: Int -> ReadS ActionCondition
$creadsPrec :: Int -> ReadS ActionCondition
Prelude.Read, Int -> ActionCondition -> ShowS
[ActionCondition] -> ShowS
ActionCondition -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ActionCondition] -> ShowS
$cshowList :: [ActionCondition] -> ShowS
show :: ActionCondition -> String
$cshow :: ActionCondition -> String
showsPrec :: Int -> ActionCondition -> ShowS
$cshowsPrec :: Int -> ActionCondition -> ShowS
Prelude.Show, forall x. Rep ActionCondition x -> ActionCondition
forall x. ActionCondition -> Rep ActionCondition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ActionCondition x -> ActionCondition
$cfrom :: forall x. ActionCondition -> Rep ActionCondition x
Prelude.Generic)

-- |
-- Create a value of 'ActionCondition' 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:
--
-- 'action', 'actionCondition_action' - The action setting that a log record must contain in order to meet the
-- condition. This is the action that WAF applied to the web request.
--
-- For rule groups, this is either the configured rule action setting, or
-- if you\'ve applied a rule action override to the rule, it\'s the
-- override action. The value @EXCLUDED_AS_COUNT@ matches on excluded rules
-- and also on rules that have a rule action override of Count.
newActionCondition ::
  -- | 'action'
  ActionValue ->
  ActionCondition
newActionCondition :: ActionValue -> ActionCondition
newActionCondition ActionValue
pAction_ =
  ActionCondition' {$sel:action:ActionCondition' :: ActionValue
action = ActionValue
pAction_}

-- | The action setting that a log record must contain in order to meet the
-- condition. This is the action that WAF applied to the web request.
--
-- For rule groups, this is either the configured rule action setting, or
-- if you\'ve applied a rule action override to the rule, it\'s the
-- override action. The value @EXCLUDED_AS_COUNT@ matches on excluded rules
-- and also on rules that have a rule action override of Count.
actionCondition_action :: Lens.Lens' ActionCondition ActionValue
actionCondition_action :: Lens' ActionCondition ActionValue
actionCondition_action = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ActionCondition' {ActionValue
action :: ActionValue
$sel:action:ActionCondition' :: ActionCondition -> ActionValue
action} -> ActionValue
action) (\s :: ActionCondition
s@ActionCondition' {} ActionValue
a -> ActionCondition
s {$sel:action:ActionCondition' :: ActionValue
action = ActionValue
a} :: ActionCondition)

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

instance Prelude.Hashable ActionCondition where
  hashWithSalt :: Int -> ActionCondition -> Int
hashWithSalt Int
_salt ActionCondition' {ActionValue
action :: ActionValue
$sel:action:ActionCondition' :: ActionCondition -> ActionValue
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ActionValue
action

instance Prelude.NFData ActionCondition where
  rnf :: ActionCondition -> ()
rnf ActionCondition' {ActionValue
action :: ActionValue
$sel:action:ActionCondition' :: ActionCondition -> ActionValue
..} = forall a. NFData a => a -> ()
Prelude.rnf ActionValue
action

instance Data.ToJSON ActionCondition where
  toJSON :: ActionCondition -> Value
toJSON ActionCondition' {ActionValue
action :: ActionValue
$sel:action:ActionCondition' :: ActionCondition -> ActionValue
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"Action" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ActionValue
action)]
      )