{-# 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.OverrideAction
-- 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.OverrideAction 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.CountAction
import Amazonka.WAFV2.Types.NoneAction

-- | The action to use in the place of the action that results from the rule
-- group evaluation. Set the override action to none to leave the result of
-- the rule group alone. Set it to count to override the result to count
-- only.
--
-- You can only use this for rule statements that reference a rule group,
-- like @RuleGroupReferenceStatement@ and @ManagedRuleGroupStatement@.
--
-- This option is usually set to none. It does not affect how the rules in
-- the rule group are evaluated. If you want the rules in the rule group to
-- only count matches, do not use this and instead use the rule action
-- override option, with @Count@ action, in your rule group reference
-- statement settings.
--
-- /See:/ 'newOverrideAction' smart constructor.
data OverrideAction = OverrideAction'
  { -- | Override the rule group evaluation result to count only.
    --
    -- This option is usually set to none. It does not affect how the rules in
    -- the rule group are evaluated. If you want the rules in the rule group to
    -- only count matches, do not use this and instead use the rule action
    -- override option, with @Count@ action, in your rule group reference
    -- statement settings.
    OverrideAction -> Maybe CountAction
count :: Prelude.Maybe CountAction,
    -- | Don\'t override the rule group evaluation result. This is the most
    -- common setting.
    OverrideAction -> Maybe NoneAction
none :: Prelude.Maybe NoneAction
  }
  deriving (OverrideAction -> OverrideAction -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OverrideAction -> OverrideAction -> Bool
$c/= :: OverrideAction -> OverrideAction -> Bool
== :: OverrideAction -> OverrideAction -> Bool
$c== :: OverrideAction -> OverrideAction -> Bool
Prelude.Eq, ReadPrec [OverrideAction]
ReadPrec OverrideAction
Int -> ReadS OverrideAction
ReadS [OverrideAction]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [OverrideAction]
$creadListPrec :: ReadPrec [OverrideAction]
readPrec :: ReadPrec OverrideAction
$creadPrec :: ReadPrec OverrideAction
readList :: ReadS [OverrideAction]
$creadList :: ReadS [OverrideAction]
readsPrec :: Int -> ReadS OverrideAction
$creadsPrec :: Int -> ReadS OverrideAction
Prelude.Read, Int -> OverrideAction -> ShowS
[OverrideAction] -> ShowS
OverrideAction -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OverrideAction] -> ShowS
$cshowList :: [OverrideAction] -> ShowS
show :: OverrideAction -> String
$cshow :: OverrideAction -> String
showsPrec :: Int -> OverrideAction -> ShowS
$cshowsPrec :: Int -> OverrideAction -> ShowS
Prelude.Show, forall x. Rep OverrideAction x -> OverrideAction
forall x. OverrideAction -> Rep OverrideAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep OverrideAction x -> OverrideAction
$cfrom :: forall x. OverrideAction -> Rep OverrideAction x
Prelude.Generic)

-- |
-- Create a value of 'OverrideAction' 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:
--
-- 'count', 'overrideAction_count' - Override the rule group evaluation result to count only.
--
-- This option is usually set to none. It does not affect how the rules in
-- the rule group are evaluated. If you want the rules in the rule group to
-- only count matches, do not use this and instead use the rule action
-- override option, with @Count@ action, in your rule group reference
-- statement settings.
--
-- 'none', 'overrideAction_none' - Don\'t override the rule group evaluation result. This is the most
-- common setting.
newOverrideAction ::
  OverrideAction
newOverrideAction :: OverrideAction
newOverrideAction =
  OverrideAction'
    { $sel:count:OverrideAction' :: Maybe CountAction
count = forall a. Maybe a
Prelude.Nothing,
      $sel:none:OverrideAction' :: Maybe NoneAction
none = forall a. Maybe a
Prelude.Nothing
    }

-- | Override the rule group evaluation result to count only.
--
-- This option is usually set to none. It does not affect how the rules in
-- the rule group are evaluated. If you want the rules in the rule group to
-- only count matches, do not use this and instead use the rule action
-- override option, with @Count@ action, in your rule group reference
-- statement settings.
overrideAction_count :: Lens.Lens' OverrideAction (Prelude.Maybe CountAction)
overrideAction_count :: Lens' OverrideAction (Maybe CountAction)
overrideAction_count = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OverrideAction' {Maybe CountAction
count :: Maybe CountAction
$sel:count:OverrideAction' :: OverrideAction -> Maybe CountAction
count} -> Maybe CountAction
count) (\s :: OverrideAction
s@OverrideAction' {} Maybe CountAction
a -> OverrideAction
s {$sel:count:OverrideAction' :: Maybe CountAction
count = Maybe CountAction
a} :: OverrideAction)

-- | Don\'t override the rule group evaluation result. This is the most
-- common setting.
overrideAction_none :: Lens.Lens' OverrideAction (Prelude.Maybe NoneAction)
overrideAction_none :: Lens' OverrideAction (Maybe NoneAction)
overrideAction_none = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OverrideAction' {Maybe NoneAction
none :: Maybe NoneAction
$sel:none:OverrideAction' :: OverrideAction -> Maybe NoneAction
none} -> Maybe NoneAction
none) (\s :: OverrideAction
s@OverrideAction' {} Maybe NoneAction
a -> OverrideAction
s {$sel:none:OverrideAction' :: Maybe NoneAction
none = Maybe NoneAction
a} :: OverrideAction)

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

instance Prelude.Hashable OverrideAction where
  hashWithSalt :: Int -> OverrideAction -> Int
hashWithSalt Int
_salt OverrideAction' {Maybe CountAction
Maybe NoneAction
none :: Maybe NoneAction
count :: Maybe CountAction
$sel:none:OverrideAction' :: OverrideAction -> Maybe NoneAction
$sel:count:OverrideAction' :: OverrideAction -> Maybe CountAction
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe CountAction
count
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe NoneAction
none

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

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