{-# 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.RuleGroupReferenceStatement
-- 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.RuleGroupReferenceStatement 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.ExcludedRule
import Amazonka.WAFV2.Types.RuleActionOverride

-- | A rule statement used to run the rules that are defined in a RuleGroup.
-- To use this, create a rule group with your rules, then provide the ARN
-- of the rule group in this statement.
--
-- You cannot nest a @RuleGroupReferenceStatement@, for example for use
-- inside a @NotStatement@ or @OrStatement@. You can only use a rule group
-- reference statement at the top level inside a web ACL.
--
-- /See:/ 'newRuleGroupReferenceStatement' smart constructor.
data RuleGroupReferenceStatement = RuleGroupReferenceStatement'
  { -- | Rules in the referenced rule group whose actions are set to @Count@.
    --
    -- Instead of this option, use @RuleActionOverrides@. It accepts any valid
    -- action setting, including @Count@.
    RuleGroupReferenceStatement -> Maybe [ExcludedRule]
excludedRules :: Prelude.Maybe [ExcludedRule],
    -- | Action settings to use in the place of the rule actions that are
    -- configured inside the rule group. You specify one override for each rule
    -- whose action you want to change.
    --
    -- You can use overrides for testing, for example you can override all of
    -- rule actions to @Count@ and then monitor the resulting count metrics to
    -- understand how the rule group would handle your web traffic. You can
    -- also permanently override some or all actions, to modify how the rule
    -- group manages your web traffic.
    RuleGroupReferenceStatement -> Maybe (NonEmpty RuleActionOverride)
ruleActionOverrides :: Prelude.Maybe (Prelude.NonEmpty RuleActionOverride),
    -- | The Amazon Resource Name (ARN) of the entity.
    RuleGroupReferenceStatement -> Text
arn :: Prelude.Text
  }
  deriving (RuleGroupReferenceStatement -> RuleGroupReferenceStatement -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RuleGroupReferenceStatement -> RuleGroupReferenceStatement -> Bool
$c/= :: RuleGroupReferenceStatement -> RuleGroupReferenceStatement -> Bool
== :: RuleGroupReferenceStatement -> RuleGroupReferenceStatement -> Bool
$c== :: RuleGroupReferenceStatement -> RuleGroupReferenceStatement -> Bool
Prelude.Eq, ReadPrec [RuleGroupReferenceStatement]
ReadPrec RuleGroupReferenceStatement
Int -> ReadS RuleGroupReferenceStatement
ReadS [RuleGroupReferenceStatement]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RuleGroupReferenceStatement]
$creadListPrec :: ReadPrec [RuleGroupReferenceStatement]
readPrec :: ReadPrec RuleGroupReferenceStatement
$creadPrec :: ReadPrec RuleGroupReferenceStatement
readList :: ReadS [RuleGroupReferenceStatement]
$creadList :: ReadS [RuleGroupReferenceStatement]
readsPrec :: Int -> ReadS RuleGroupReferenceStatement
$creadsPrec :: Int -> ReadS RuleGroupReferenceStatement
Prelude.Read, Int -> RuleGroupReferenceStatement -> ShowS
[RuleGroupReferenceStatement] -> ShowS
RuleGroupReferenceStatement -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RuleGroupReferenceStatement] -> ShowS
$cshowList :: [RuleGroupReferenceStatement] -> ShowS
show :: RuleGroupReferenceStatement -> String
$cshow :: RuleGroupReferenceStatement -> String
showsPrec :: Int -> RuleGroupReferenceStatement -> ShowS
$cshowsPrec :: Int -> RuleGroupReferenceStatement -> ShowS
Prelude.Show, forall x.
Rep RuleGroupReferenceStatement x -> RuleGroupReferenceStatement
forall x.
RuleGroupReferenceStatement -> Rep RuleGroupReferenceStatement x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep RuleGroupReferenceStatement x -> RuleGroupReferenceStatement
$cfrom :: forall x.
RuleGroupReferenceStatement -> Rep RuleGroupReferenceStatement x
Prelude.Generic)

-- |
-- Create a value of 'RuleGroupReferenceStatement' 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:
--
-- 'excludedRules', 'ruleGroupReferenceStatement_excludedRules' - Rules in the referenced rule group whose actions are set to @Count@.
--
-- Instead of this option, use @RuleActionOverrides@. It accepts any valid
-- action setting, including @Count@.
--
-- 'ruleActionOverrides', 'ruleGroupReferenceStatement_ruleActionOverrides' - Action settings to use in the place of the rule actions that are
-- configured inside the rule group. You specify one override for each rule
-- whose action you want to change.
--
-- You can use overrides for testing, for example you can override all of
-- rule actions to @Count@ and then monitor the resulting count metrics to
-- understand how the rule group would handle your web traffic. You can
-- also permanently override some or all actions, to modify how the rule
-- group manages your web traffic.
--
-- 'arn', 'ruleGroupReferenceStatement_arn' - The Amazon Resource Name (ARN) of the entity.
newRuleGroupReferenceStatement ::
  -- | 'arn'
  Prelude.Text ->
  RuleGroupReferenceStatement
newRuleGroupReferenceStatement :: Text -> RuleGroupReferenceStatement
newRuleGroupReferenceStatement Text
pARN_ =
  RuleGroupReferenceStatement'
    { $sel:excludedRules:RuleGroupReferenceStatement' :: Maybe [ExcludedRule]
excludedRules =
        forall a. Maybe a
Prelude.Nothing,
      $sel:ruleActionOverrides:RuleGroupReferenceStatement' :: Maybe (NonEmpty RuleActionOverride)
ruleActionOverrides = forall a. Maybe a
Prelude.Nothing,
      $sel:arn:RuleGroupReferenceStatement' :: Text
arn = Text
pARN_
    }

-- | Rules in the referenced rule group whose actions are set to @Count@.
--
-- Instead of this option, use @RuleActionOverrides@. It accepts any valid
-- action setting, including @Count@.
ruleGroupReferenceStatement_excludedRules :: Lens.Lens' RuleGroupReferenceStatement (Prelude.Maybe [ExcludedRule])
ruleGroupReferenceStatement_excludedRules :: Lens' RuleGroupReferenceStatement (Maybe [ExcludedRule])
ruleGroupReferenceStatement_excludedRules = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RuleGroupReferenceStatement' {Maybe [ExcludedRule]
excludedRules :: Maybe [ExcludedRule]
$sel:excludedRules:RuleGroupReferenceStatement' :: RuleGroupReferenceStatement -> Maybe [ExcludedRule]
excludedRules} -> Maybe [ExcludedRule]
excludedRules) (\s :: RuleGroupReferenceStatement
s@RuleGroupReferenceStatement' {} Maybe [ExcludedRule]
a -> RuleGroupReferenceStatement
s {$sel:excludedRules:RuleGroupReferenceStatement' :: Maybe [ExcludedRule]
excludedRules = Maybe [ExcludedRule]
a} :: RuleGroupReferenceStatement) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Action settings to use in the place of the rule actions that are
-- configured inside the rule group. You specify one override for each rule
-- whose action you want to change.
--
-- You can use overrides for testing, for example you can override all of
-- rule actions to @Count@ and then monitor the resulting count metrics to
-- understand how the rule group would handle your web traffic. You can
-- also permanently override some or all actions, to modify how the rule
-- group manages your web traffic.
ruleGroupReferenceStatement_ruleActionOverrides :: Lens.Lens' RuleGroupReferenceStatement (Prelude.Maybe (Prelude.NonEmpty RuleActionOverride))
ruleGroupReferenceStatement_ruleActionOverrides :: Lens'
  RuleGroupReferenceStatement (Maybe (NonEmpty RuleActionOverride))
ruleGroupReferenceStatement_ruleActionOverrides = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RuleGroupReferenceStatement' {Maybe (NonEmpty RuleActionOverride)
ruleActionOverrides :: Maybe (NonEmpty RuleActionOverride)
$sel:ruleActionOverrides:RuleGroupReferenceStatement' :: RuleGroupReferenceStatement -> Maybe (NonEmpty RuleActionOverride)
ruleActionOverrides} -> Maybe (NonEmpty RuleActionOverride)
ruleActionOverrides) (\s :: RuleGroupReferenceStatement
s@RuleGroupReferenceStatement' {} Maybe (NonEmpty RuleActionOverride)
a -> RuleGroupReferenceStatement
s {$sel:ruleActionOverrides:RuleGroupReferenceStatement' :: Maybe (NonEmpty RuleActionOverride)
ruleActionOverrides = Maybe (NonEmpty RuleActionOverride)
a} :: RuleGroupReferenceStatement) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The Amazon Resource Name (ARN) of the entity.
ruleGroupReferenceStatement_arn :: Lens.Lens' RuleGroupReferenceStatement Prelude.Text
ruleGroupReferenceStatement_arn :: Lens' RuleGroupReferenceStatement Text
ruleGroupReferenceStatement_arn = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RuleGroupReferenceStatement' {Text
arn :: Text
$sel:arn:RuleGroupReferenceStatement' :: RuleGroupReferenceStatement -> Text
arn} -> Text
arn) (\s :: RuleGroupReferenceStatement
s@RuleGroupReferenceStatement' {} Text
a -> RuleGroupReferenceStatement
s {$sel:arn:RuleGroupReferenceStatement' :: Text
arn = Text
a} :: RuleGroupReferenceStatement)

instance Data.FromJSON RuleGroupReferenceStatement where
  parseJSON :: Value -> Parser RuleGroupReferenceStatement
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"RuleGroupReferenceStatement"
      ( \Object
x ->
          Maybe [ExcludedRule]
-> Maybe (NonEmpty RuleActionOverride)
-> Text
-> RuleGroupReferenceStatement
RuleGroupReferenceStatement'
            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
"ExcludedRules" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            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
"RuleActionOverrides")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"ARN")
      )

instance Prelude.Hashable RuleGroupReferenceStatement where
  hashWithSalt :: Int -> RuleGroupReferenceStatement -> Int
hashWithSalt Int
_salt RuleGroupReferenceStatement' {Maybe [ExcludedRule]
Maybe (NonEmpty RuleActionOverride)
Text
arn :: Text
ruleActionOverrides :: Maybe (NonEmpty RuleActionOverride)
excludedRules :: Maybe [ExcludedRule]
$sel:arn:RuleGroupReferenceStatement' :: RuleGroupReferenceStatement -> Text
$sel:ruleActionOverrides:RuleGroupReferenceStatement' :: RuleGroupReferenceStatement -> Maybe (NonEmpty RuleActionOverride)
$sel:excludedRules:RuleGroupReferenceStatement' :: RuleGroupReferenceStatement -> Maybe [ExcludedRule]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [ExcludedRule]
excludedRules
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty RuleActionOverride)
ruleActionOverrides
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
arn

instance Prelude.NFData RuleGroupReferenceStatement where
  rnf :: RuleGroupReferenceStatement -> ()
rnf RuleGroupReferenceStatement' {Maybe [ExcludedRule]
Maybe (NonEmpty RuleActionOverride)
Text
arn :: Text
ruleActionOverrides :: Maybe (NonEmpty RuleActionOverride)
excludedRules :: Maybe [ExcludedRule]
$sel:arn:RuleGroupReferenceStatement' :: RuleGroupReferenceStatement -> Text
$sel:ruleActionOverrides:RuleGroupReferenceStatement' :: RuleGroupReferenceStatement -> Maybe (NonEmpty RuleActionOverride)
$sel:excludedRules:RuleGroupReferenceStatement' :: RuleGroupReferenceStatement -> Maybe [ExcludedRule]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [ExcludedRule]
excludedRules
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty RuleActionOverride)
ruleActionOverrides
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
arn

instance Data.ToJSON RuleGroupReferenceStatement where
  toJSON :: RuleGroupReferenceStatement -> Value
toJSON RuleGroupReferenceStatement' {Maybe [ExcludedRule]
Maybe (NonEmpty RuleActionOverride)
Text
arn :: Text
ruleActionOverrides :: Maybe (NonEmpty RuleActionOverride)
excludedRules :: Maybe [ExcludedRule]
$sel:arn:RuleGroupReferenceStatement' :: RuleGroupReferenceStatement -> Text
$sel:ruleActionOverrides:RuleGroupReferenceStatement' :: RuleGroupReferenceStatement -> Maybe (NonEmpty RuleActionOverride)
$sel:excludedRules:RuleGroupReferenceStatement' :: RuleGroupReferenceStatement -> Maybe [ExcludedRule]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"ExcludedRules" 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 [ExcludedRule]
excludedRules,
            (Key
"RuleActionOverrides" 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 (NonEmpty RuleActionOverride)
ruleActionOverrides,
            forall a. a -> Maybe a
Prelude.Just (Key
"ARN" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
arn)
          ]
      )