{-# 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.Condition
-- 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.Condition 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.ActionCondition
import Amazonka.WAFV2.Types.LabelNameCondition

-- | A single match condition for a Filter.
--
-- /See:/ 'newCondition' smart constructor.
data Condition = Condition'
  { -- | A single action condition. This is the action setting that a log record
    -- must contain in order to meet the condition.
    Condition -> Maybe ActionCondition
actionCondition :: Prelude.Maybe ActionCondition,
    -- | A single label name condition. This is the fully qualified label name
    -- that a log record must contain in order to meet the condition. Fully
    -- qualified labels have a prefix, optional namespaces, and label name. The
    -- prefix identifies the rule group or web ACL context of the rule that
    -- added the label.
    Condition -> Maybe LabelNameCondition
labelNameCondition :: Prelude.Maybe LabelNameCondition
  }
  deriving (Condition -> Condition -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Condition -> Condition -> Bool
$c/= :: Condition -> Condition -> Bool
== :: Condition -> Condition -> Bool
$c== :: Condition -> Condition -> Bool
Prelude.Eq, ReadPrec [Condition]
ReadPrec Condition
Int -> ReadS Condition
ReadS [Condition]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Condition]
$creadListPrec :: ReadPrec [Condition]
readPrec :: ReadPrec Condition
$creadPrec :: ReadPrec Condition
readList :: ReadS [Condition]
$creadList :: ReadS [Condition]
readsPrec :: Int -> ReadS Condition
$creadsPrec :: Int -> ReadS Condition
Prelude.Read, Int -> Condition -> ShowS
[Condition] -> ShowS
Condition -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Condition] -> ShowS
$cshowList :: [Condition] -> ShowS
show :: Condition -> String
$cshow :: Condition -> String
showsPrec :: Int -> Condition -> ShowS
$cshowsPrec :: Int -> Condition -> ShowS
Prelude.Show, forall x. Rep Condition x -> Condition
forall x. Condition -> Rep Condition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Condition x -> Condition
$cfrom :: forall x. Condition -> Rep Condition x
Prelude.Generic)

-- |
-- Create a value of 'Condition' 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:
--
-- 'actionCondition', 'condition_actionCondition' - A single action condition. This is the action setting that a log record
-- must contain in order to meet the condition.
--
-- 'labelNameCondition', 'condition_labelNameCondition' - A single label name condition. This is the fully qualified label name
-- that a log record must contain in order to meet the condition. Fully
-- qualified labels have a prefix, optional namespaces, and label name. The
-- prefix identifies the rule group or web ACL context of the rule that
-- added the label.
newCondition ::
  Condition
newCondition :: Condition
newCondition =
  Condition'
    { $sel:actionCondition:Condition' :: Maybe ActionCondition
actionCondition = forall a. Maybe a
Prelude.Nothing,
      $sel:labelNameCondition:Condition' :: Maybe LabelNameCondition
labelNameCondition = forall a. Maybe a
Prelude.Nothing
    }

-- | A single action condition. This is the action setting that a log record
-- must contain in order to meet the condition.
condition_actionCondition :: Lens.Lens' Condition (Prelude.Maybe ActionCondition)
condition_actionCondition :: Lens' Condition (Maybe ActionCondition)
condition_actionCondition = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Condition' {Maybe ActionCondition
actionCondition :: Maybe ActionCondition
$sel:actionCondition:Condition' :: Condition -> Maybe ActionCondition
actionCondition} -> Maybe ActionCondition
actionCondition) (\s :: Condition
s@Condition' {} Maybe ActionCondition
a -> Condition
s {$sel:actionCondition:Condition' :: Maybe ActionCondition
actionCondition = Maybe ActionCondition
a} :: Condition)

-- | A single label name condition. This is the fully qualified label name
-- that a log record must contain in order to meet the condition. Fully
-- qualified labels have a prefix, optional namespaces, and label name. The
-- prefix identifies the rule group or web ACL context of the rule that
-- added the label.
condition_labelNameCondition :: Lens.Lens' Condition (Prelude.Maybe LabelNameCondition)
condition_labelNameCondition :: Lens' Condition (Maybe LabelNameCondition)
condition_labelNameCondition = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Condition' {Maybe LabelNameCondition
labelNameCondition :: Maybe LabelNameCondition
$sel:labelNameCondition:Condition' :: Condition -> Maybe LabelNameCondition
labelNameCondition} -> Maybe LabelNameCondition
labelNameCondition) (\s :: Condition
s@Condition' {} Maybe LabelNameCondition
a -> Condition
s {$sel:labelNameCondition:Condition' :: Maybe LabelNameCondition
labelNameCondition = Maybe LabelNameCondition
a} :: Condition)

instance Data.FromJSON Condition where
  parseJSON :: Value -> Parser Condition
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Condition"
      ( \Object
x ->
          Maybe ActionCondition -> Maybe LabelNameCondition -> Condition
Condition'
            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
"ActionCondition")
            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
"LabelNameCondition")
      )

instance Prelude.Hashable Condition where
  hashWithSalt :: Int -> Condition -> Int
hashWithSalt Int
_salt Condition' {Maybe ActionCondition
Maybe LabelNameCondition
labelNameCondition :: Maybe LabelNameCondition
actionCondition :: Maybe ActionCondition
$sel:labelNameCondition:Condition' :: Condition -> Maybe LabelNameCondition
$sel:actionCondition:Condition' :: Condition -> Maybe ActionCondition
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ActionCondition
actionCondition
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe LabelNameCondition
labelNameCondition

instance Prelude.NFData Condition where
  rnf :: Condition -> ()
rnf Condition' {Maybe ActionCondition
Maybe LabelNameCondition
labelNameCondition :: Maybe LabelNameCondition
actionCondition :: Maybe ActionCondition
$sel:labelNameCondition:Condition' :: Condition -> Maybe LabelNameCondition
$sel:actionCondition:Condition' :: Condition -> Maybe ActionCondition
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe ActionCondition
actionCondition
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe LabelNameCondition
labelNameCondition

instance Data.ToJSON Condition where
  toJSON :: Condition -> Value
toJSON Condition' {Maybe ActionCondition
Maybe LabelNameCondition
labelNameCondition :: Maybe LabelNameCondition
actionCondition :: Maybe ActionCondition
$sel:labelNameCondition:Condition' :: Condition -> Maybe LabelNameCondition
$sel:actionCondition:Condition' :: Condition -> Maybe ActionCondition
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"ActionCondition" 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 ActionCondition
actionCondition,
            (Key
"LabelNameCondition" 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 LabelNameCondition
labelNameCondition
          ]
      )