{-# 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.WAF.Types.RuleUpdate
-- 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.WAF.Types.RuleUpdate 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.WAF.Types.ChangeAction
import Amazonka.WAF.Types.Predicate

-- | This is __AWS WAF Classic__ documentation. For more information, see
-- <https://docs.aws.amazon.com/waf/latest/developerguide/classic-waf-chapter.html AWS WAF Classic>
-- in the developer guide.
--
-- __For the latest version of AWS WAF__, use the AWS WAFV2 API and see the
-- <https://docs.aws.amazon.com/waf/latest/developerguide/waf-chapter.html AWS WAF Developer Guide>.
-- With the latest version, AWS WAF has a single set of endpoints for
-- regional and global use.
--
-- Specifies a @Predicate@ (such as an @IPSet@) and indicates whether you
-- want to add it to a @Rule@ or delete it from a @Rule@.
--
-- /See:/ 'newRuleUpdate' smart constructor.
data RuleUpdate = RuleUpdate'
  { -- | Specify @INSERT@ to add a @Predicate@ to a @Rule@. Use @DELETE@ to
    -- remove a @Predicate@ from a @Rule@.
    RuleUpdate -> ChangeAction
action :: ChangeAction,
    -- | The ID of the @Predicate@ (such as an @IPSet@) that you want to add to a
    -- @Rule@.
    RuleUpdate -> Predicate
predicate :: Predicate
  }
  deriving (RuleUpdate -> RuleUpdate -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RuleUpdate -> RuleUpdate -> Bool
$c/= :: RuleUpdate -> RuleUpdate -> Bool
== :: RuleUpdate -> RuleUpdate -> Bool
$c== :: RuleUpdate -> RuleUpdate -> Bool
Prelude.Eq, ReadPrec [RuleUpdate]
ReadPrec RuleUpdate
Int -> ReadS RuleUpdate
ReadS [RuleUpdate]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RuleUpdate]
$creadListPrec :: ReadPrec [RuleUpdate]
readPrec :: ReadPrec RuleUpdate
$creadPrec :: ReadPrec RuleUpdate
readList :: ReadS [RuleUpdate]
$creadList :: ReadS [RuleUpdate]
readsPrec :: Int -> ReadS RuleUpdate
$creadsPrec :: Int -> ReadS RuleUpdate
Prelude.Read, Int -> RuleUpdate -> ShowS
[RuleUpdate] -> ShowS
RuleUpdate -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RuleUpdate] -> ShowS
$cshowList :: [RuleUpdate] -> ShowS
show :: RuleUpdate -> String
$cshow :: RuleUpdate -> String
showsPrec :: Int -> RuleUpdate -> ShowS
$cshowsPrec :: Int -> RuleUpdate -> ShowS
Prelude.Show, forall x. Rep RuleUpdate x -> RuleUpdate
forall x. RuleUpdate -> Rep RuleUpdate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RuleUpdate x -> RuleUpdate
$cfrom :: forall x. RuleUpdate -> Rep RuleUpdate x
Prelude.Generic)

-- |
-- Create a value of 'RuleUpdate' 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', 'ruleUpdate_action' - Specify @INSERT@ to add a @Predicate@ to a @Rule@. Use @DELETE@ to
-- remove a @Predicate@ from a @Rule@.
--
-- 'predicate', 'ruleUpdate_predicate' - The ID of the @Predicate@ (such as an @IPSet@) that you want to add to a
-- @Rule@.
newRuleUpdate ::
  -- | 'action'
  ChangeAction ->
  -- | 'predicate'
  Predicate ->
  RuleUpdate
newRuleUpdate :: ChangeAction -> Predicate -> RuleUpdate
newRuleUpdate ChangeAction
pAction_ Predicate
pPredicate_ =
  RuleUpdate'
    { $sel:action:RuleUpdate' :: ChangeAction
action = ChangeAction
pAction_,
      $sel:predicate:RuleUpdate' :: Predicate
predicate = Predicate
pPredicate_
    }

-- | Specify @INSERT@ to add a @Predicate@ to a @Rule@. Use @DELETE@ to
-- remove a @Predicate@ from a @Rule@.
ruleUpdate_action :: Lens.Lens' RuleUpdate ChangeAction
ruleUpdate_action :: Lens' RuleUpdate ChangeAction
ruleUpdate_action = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RuleUpdate' {ChangeAction
action :: ChangeAction
$sel:action:RuleUpdate' :: RuleUpdate -> ChangeAction
action} -> ChangeAction
action) (\s :: RuleUpdate
s@RuleUpdate' {} ChangeAction
a -> RuleUpdate
s {$sel:action:RuleUpdate' :: ChangeAction
action = ChangeAction
a} :: RuleUpdate)

-- | The ID of the @Predicate@ (such as an @IPSet@) that you want to add to a
-- @Rule@.
ruleUpdate_predicate :: Lens.Lens' RuleUpdate Predicate
ruleUpdate_predicate :: Lens' RuleUpdate Predicate
ruleUpdate_predicate = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RuleUpdate' {Predicate
predicate :: Predicate
$sel:predicate:RuleUpdate' :: RuleUpdate -> Predicate
predicate} -> Predicate
predicate) (\s :: RuleUpdate
s@RuleUpdate' {} Predicate
a -> RuleUpdate
s {$sel:predicate:RuleUpdate' :: Predicate
predicate = Predicate
a} :: RuleUpdate)

instance Prelude.Hashable RuleUpdate where
  hashWithSalt :: Int -> RuleUpdate -> Int
hashWithSalt Int
_salt RuleUpdate' {ChangeAction
Predicate
predicate :: Predicate
action :: ChangeAction
$sel:predicate:RuleUpdate' :: RuleUpdate -> Predicate
$sel:action:RuleUpdate' :: RuleUpdate -> ChangeAction
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ChangeAction
action
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Predicate
predicate

instance Prelude.NFData RuleUpdate where
  rnf :: RuleUpdate -> ()
rnf RuleUpdate' {ChangeAction
Predicate
predicate :: Predicate
action :: ChangeAction
$sel:predicate:RuleUpdate' :: RuleUpdate -> Predicate
$sel:action:RuleUpdate' :: RuleUpdate -> ChangeAction
..} =
    forall a. NFData a => a -> ()
Prelude.rnf ChangeAction
action
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Predicate
predicate

instance Data.ToJSON RuleUpdate where
  toJSON :: RuleUpdate -> Value
toJSON RuleUpdate' {ChangeAction
Predicate
predicate :: Predicate
action :: ChangeAction
$sel:predicate:RuleUpdate' :: RuleUpdate -> Predicate
$sel:action:RuleUpdate' :: RuleUpdate -> ChangeAction
..} =
    [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..= ChangeAction
action),
            forall a. a -> Maybe a
Prelude.Just (Key
"Predicate" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Predicate
predicate)
          ]
      )