{-# 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.Predicate
-- 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.Predicate where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.WAFRegional.Types.PredicateType

-- | 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 the ByteMatchSet, IPSet, SqlInjectionMatchSet, XssMatchSet,
-- RegexMatchSet, GeoMatchSet, and SizeConstraintSet objects that you want
-- to add to a @Rule@ and, for each object, indicates whether you want to
-- negate the settings, for example, requests that do NOT originate from
-- the IP address 192.0.2.44.
--
-- /See:/ 'newPredicate' smart constructor.
data Predicate = Predicate'
  { -- | Set @Negated@ to @False@ if you want AWS WAF to allow, block, or count
    -- requests based on the settings in the specified ByteMatchSet, IPSet,
    -- SqlInjectionMatchSet, XssMatchSet, RegexMatchSet, GeoMatchSet, or
    -- SizeConstraintSet. For example, if an @IPSet@ includes the IP address
    -- @192.0.2.44@, AWS WAF will allow or block requests based on that IP
    -- address.
    --
    -- Set @Negated@ to @True@ if you want AWS WAF to allow or block a request
    -- based on the negation of the settings in the ByteMatchSet, IPSet,
    -- SqlInjectionMatchSet, XssMatchSet, RegexMatchSet, GeoMatchSet, or
    -- SizeConstraintSet. For example, if an @IPSet@ includes the IP address
    -- @192.0.2.44@, AWS WAF will allow, block, or count requests based on all
    -- IP addresses /except/ @192.0.2.44@.
    Predicate -> Bool
negated :: Prelude.Bool,
    -- | The type of predicate in a @Rule@, such as @ByteMatch@ or @IPSet@.
    Predicate -> PredicateType
type' :: PredicateType,
    -- | A unique identifier for a predicate in a @Rule@, such as
    -- @ByteMatchSetId@ or @IPSetId@. The ID is returned by the corresponding
    -- @Create@ or @List@ command.
    Predicate -> Text
dataId :: Prelude.Text
  }
  deriving (Predicate -> Predicate -> Bool
(Predicate -> Predicate -> Bool)
-> (Predicate -> Predicate -> Bool) -> Eq Predicate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Predicate -> Predicate -> Bool
$c/= :: Predicate -> Predicate -> Bool
== :: Predicate -> Predicate -> Bool
$c== :: Predicate -> Predicate -> Bool
Prelude.Eq, ReadPrec [Predicate]
ReadPrec Predicate
Int -> ReadS Predicate
ReadS [Predicate]
(Int -> ReadS Predicate)
-> ReadS [Predicate]
-> ReadPrec Predicate
-> ReadPrec [Predicate]
-> Read Predicate
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Predicate]
$creadListPrec :: ReadPrec [Predicate]
readPrec :: ReadPrec Predicate
$creadPrec :: ReadPrec Predicate
readList :: ReadS [Predicate]
$creadList :: ReadS [Predicate]
readsPrec :: Int -> ReadS Predicate
$creadsPrec :: Int -> ReadS Predicate
Prelude.Read, Int -> Predicate -> ShowS
[Predicate] -> ShowS
Predicate -> String
(Int -> Predicate -> ShowS)
-> (Predicate -> String)
-> ([Predicate] -> ShowS)
-> Show Predicate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Predicate] -> ShowS
$cshowList :: [Predicate] -> ShowS
show :: Predicate -> String
$cshow :: Predicate -> String
showsPrec :: Int -> Predicate -> ShowS
$cshowsPrec :: Int -> Predicate -> ShowS
Prelude.Show, (forall x. Predicate -> Rep Predicate x)
-> (forall x. Rep Predicate x -> Predicate) -> Generic Predicate
forall x. Rep Predicate x -> Predicate
forall x. Predicate -> Rep Predicate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Predicate x -> Predicate
$cfrom :: forall x. Predicate -> Rep Predicate x
Prelude.Generic)

-- |
-- Create a value of 'Predicate' 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:
--
-- 'negated', 'predicate_negated' - Set @Negated@ to @False@ if you want AWS WAF to allow, block, or count
-- requests based on the settings in the specified ByteMatchSet, IPSet,
-- SqlInjectionMatchSet, XssMatchSet, RegexMatchSet, GeoMatchSet, or
-- SizeConstraintSet. For example, if an @IPSet@ includes the IP address
-- @192.0.2.44@, AWS WAF will allow or block requests based on that IP
-- address.
--
-- Set @Negated@ to @True@ if you want AWS WAF to allow or block a request
-- based on the negation of the settings in the ByteMatchSet, IPSet,
-- SqlInjectionMatchSet, XssMatchSet, RegexMatchSet, GeoMatchSet, or
-- SizeConstraintSet. For example, if an @IPSet@ includes the IP address
-- @192.0.2.44@, AWS WAF will allow, block, or count requests based on all
-- IP addresses /except/ @192.0.2.44@.
--
-- 'type'', 'predicate_type' - The type of predicate in a @Rule@, such as @ByteMatch@ or @IPSet@.
--
-- 'dataId', 'predicate_dataId' - A unique identifier for a predicate in a @Rule@, such as
-- @ByteMatchSetId@ or @IPSetId@. The ID is returned by the corresponding
-- @Create@ or @List@ command.
newPredicate ::
  -- | 'negated'
  Prelude.Bool ->
  -- | 'type''
  PredicateType ->
  -- | 'dataId'
  Prelude.Text ->
  Predicate
newPredicate :: Bool -> PredicateType -> Text -> Predicate
newPredicate Bool
pNegated_ PredicateType
pType_ Text
pDataId_ =
  Predicate' :: Bool -> PredicateType -> Text -> Predicate
Predicate'
    { $sel:negated:Predicate' :: Bool
negated = Bool
pNegated_,
      $sel:type':Predicate' :: PredicateType
type' = PredicateType
pType_,
      $sel:dataId:Predicate' :: Text
dataId = Text
pDataId_
    }

-- | Set @Negated@ to @False@ if you want AWS WAF to allow, block, or count
-- requests based on the settings in the specified ByteMatchSet, IPSet,
-- SqlInjectionMatchSet, XssMatchSet, RegexMatchSet, GeoMatchSet, or
-- SizeConstraintSet. For example, if an @IPSet@ includes the IP address
-- @192.0.2.44@, AWS WAF will allow or block requests based on that IP
-- address.
--
-- Set @Negated@ to @True@ if you want AWS WAF to allow or block a request
-- based on the negation of the settings in the ByteMatchSet, IPSet,
-- SqlInjectionMatchSet, XssMatchSet, RegexMatchSet, GeoMatchSet, or
-- SizeConstraintSet. For example, if an @IPSet@ includes the IP address
-- @192.0.2.44@, AWS WAF will allow, block, or count requests based on all
-- IP addresses /except/ @192.0.2.44@.
predicate_negated :: Lens.Lens' Predicate Prelude.Bool
predicate_negated :: (Bool -> f Bool) -> Predicate -> f Predicate
predicate_negated = (Predicate -> Bool)
-> (Predicate -> Bool -> Predicate)
-> Lens Predicate Predicate Bool Bool
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Predicate' {Bool
negated :: Bool
$sel:negated:Predicate' :: Predicate -> Bool
negated} -> Bool
negated) (\s :: Predicate
s@Predicate' {} Bool
a -> Predicate
s {$sel:negated:Predicate' :: Bool
negated = Bool
a} :: Predicate)

-- | The type of predicate in a @Rule@, such as @ByteMatch@ or @IPSet@.
predicate_type :: Lens.Lens' Predicate PredicateType
predicate_type :: (PredicateType -> f PredicateType) -> Predicate -> f Predicate
predicate_type = (Predicate -> PredicateType)
-> (Predicate -> PredicateType -> Predicate)
-> Lens Predicate Predicate PredicateType PredicateType
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Predicate' {PredicateType
type' :: PredicateType
$sel:type':Predicate' :: Predicate -> PredicateType
type'} -> PredicateType
type') (\s :: Predicate
s@Predicate' {} PredicateType
a -> Predicate
s {$sel:type':Predicate' :: PredicateType
type' = PredicateType
a} :: Predicate)

-- | A unique identifier for a predicate in a @Rule@, such as
-- @ByteMatchSetId@ or @IPSetId@. The ID is returned by the corresponding
-- @Create@ or @List@ command.
predicate_dataId :: Lens.Lens' Predicate Prelude.Text
predicate_dataId :: (Text -> f Text) -> Predicate -> f Predicate
predicate_dataId = (Predicate -> Text)
-> (Predicate -> Text -> Predicate)
-> Lens Predicate Predicate Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Predicate' {Text
dataId :: Text
$sel:dataId:Predicate' :: Predicate -> Text
dataId} -> Text
dataId) (\s :: Predicate
s@Predicate' {} Text
a -> Predicate
s {$sel:dataId:Predicate' :: Text
dataId = Text
a} :: Predicate)

instance Core.FromJSON Predicate where
  parseJSON :: Value -> Parser Predicate
parseJSON =
    String -> (Object -> Parser Predicate) -> Value -> Parser Predicate
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Predicate"
      ( \Object
x ->
          Bool -> PredicateType -> Text -> Predicate
Predicate'
            (Bool -> PredicateType -> Text -> Predicate)
-> Parser Bool -> Parser (PredicateType -> Text -> Predicate)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Bool
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Negated")
            Parser (PredicateType -> Text -> Predicate)
-> Parser PredicateType -> Parser (Text -> Predicate)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser PredicateType
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Type")
            Parser (Text -> Predicate) -> Parser Text -> Parser Predicate
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"DataId")
      )

instance Prelude.Hashable Predicate

instance Prelude.NFData Predicate

instance Core.ToJSON Predicate where
  toJSON :: Predicate -> Value
toJSON Predicate' {Bool
Text
PredicateType
dataId :: Text
type' :: PredicateType
negated :: Bool
$sel:dataId:Predicate' :: Predicate -> Text
$sel:type':Predicate' :: Predicate -> PredicateType
$sel:negated:Predicate' :: Predicate -> Bool
..} =
    [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
"Negated" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Bool
negated),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Type" Text -> PredicateType -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= PredicateType
type'),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"DataId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
dataId)
          ]
      )