{-# 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.WAFRegional.Types.RuleUpdate
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.WAFRegional.Types.RuleUpdate where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.WAFRegional.Types.ChangeAction
import Amazonka.WAFRegional.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
(RuleUpdate -> RuleUpdate -> Bool)
-> (RuleUpdate -> RuleUpdate -> Bool) -> Eq RuleUpdate
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]
(Int -> ReadS RuleUpdate)
-> ReadS [RuleUpdate]
-> ReadPrec RuleUpdate
-> ReadPrec [RuleUpdate]
-> Read 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
(Int -> RuleUpdate -> ShowS)
-> (RuleUpdate -> String)
-> ([RuleUpdate] -> ShowS)
-> Show RuleUpdate
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. RuleUpdate -> Rep RuleUpdate x)
-> (forall x. Rep RuleUpdate x -> RuleUpdate) -> Generic RuleUpdate
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' :: ChangeAction -> Predicate -> RuleUpdate
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 :: (ChangeAction -> f ChangeAction) -> RuleUpdate -> f RuleUpdate
ruleUpdate_action = (RuleUpdate -> ChangeAction)
-> (RuleUpdate -> ChangeAction -> RuleUpdate)
-> Lens RuleUpdate RuleUpdate ChangeAction ChangeAction
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 :: (Predicate -> f Predicate) -> RuleUpdate -> f RuleUpdate
ruleUpdate_predicate = (RuleUpdate -> Predicate)
-> (RuleUpdate -> Predicate -> RuleUpdate)
-> Lens RuleUpdate RuleUpdate Predicate 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

instance Prelude.NFData RuleUpdate

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Action" Text -> ChangeAction -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ChangeAction
action),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Predicate" Text -> Predicate -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Predicate
predicate)
          ]
      )