{-# 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.LabelMatchStatement
-- 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.LabelMatchStatement 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.LabelMatchScope

-- | A rule statement to match against labels that have been added to the web
-- request by rules that have already run in the web ACL.
--
-- The label match statement provides the label or namespace string to
-- search for. The label string can represent a part or all of the fully
-- qualified label name that had been added to the web request. 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. If you do not provide the fully qualified name in your
-- label match string, WAF performs the search for labels that were added
-- in the same context as the label match statement.
--
-- /See:/ 'newLabelMatchStatement' smart constructor.
data LabelMatchStatement = LabelMatchStatement'
  { -- | Specify whether you want to match using the label name or just the
    -- namespace.
    LabelMatchStatement -> LabelMatchScope
scope :: LabelMatchScope,
    -- | The string to match against. The setting you provide for this depends on
    -- the match statement\'s @Scope@ setting:
    --
    -- -   If the @Scope@ indicates @LABEL@, then this specification must
    --     include the name and can include any number of preceding namespace
    --     specifications and prefix up to providing the fully qualified label
    --     name.
    --
    -- -   If the @Scope@ indicates @NAMESPACE@, then this specification can
    --     include any number of contiguous namespace strings, and can include
    --     the entire label namespace prefix from the rule group or web ACL
    --     where the label originates.
    --
    -- Labels are case sensitive and components of a label must be separated by
    -- colon, for example @NS1:NS2:name@.
    LabelMatchStatement -> Text
key :: Prelude.Text
  }
  deriving (LabelMatchStatement -> LabelMatchStatement -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LabelMatchStatement -> LabelMatchStatement -> Bool
$c/= :: LabelMatchStatement -> LabelMatchStatement -> Bool
== :: LabelMatchStatement -> LabelMatchStatement -> Bool
$c== :: LabelMatchStatement -> LabelMatchStatement -> Bool
Prelude.Eq, ReadPrec [LabelMatchStatement]
ReadPrec LabelMatchStatement
Int -> ReadS LabelMatchStatement
ReadS [LabelMatchStatement]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LabelMatchStatement]
$creadListPrec :: ReadPrec [LabelMatchStatement]
readPrec :: ReadPrec LabelMatchStatement
$creadPrec :: ReadPrec LabelMatchStatement
readList :: ReadS [LabelMatchStatement]
$creadList :: ReadS [LabelMatchStatement]
readsPrec :: Int -> ReadS LabelMatchStatement
$creadsPrec :: Int -> ReadS LabelMatchStatement
Prelude.Read, Int -> LabelMatchStatement -> ShowS
[LabelMatchStatement] -> ShowS
LabelMatchStatement -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LabelMatchStatement] -> ShowS
$cshowList :: [LabelMatchStatement] -> ShowS
show :: LabelMatchStatement -> String
$cshow :: LabelMatchStatement -> String
showsPrec :: Int -> LabelMatchStatement -> ShowS
$cshowsPrec :: Int -> LabelMatchStatement -> ShowS
Prelude.Show, forall x. Rep LabelMatchStatement x -> LabelMatchStatement
forall x. LabelMatchStatement -> Rep LabelMatchStatement x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LabelMatchStatement x -> LabelMatchStatement
$cfrom :: forall x. LabelMatchStatement -> Rep LabelMatchStatement x
Prelude.Generic)

-- |
-- Create a value of 'LabelMatchStatement' 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:
--
-- 'scope', 'labelMatchStatement_scope' - Specify whether you want to match using the label name or just the
-- namespace.
--
-- 'key', 'labelMatchStatement_key' - The string to match against. The setting you provide for this depends on
-- the match statement\'s @Scope@ setting:
--
-- -   If the @Scope@ indicates @LABEL@, then this specification must
--     include the name and can include any number of preceding namespace
--     specifications and prefix up to providing the fully qualified label
--     name.
--
-- -   If the @Scope@ indicates @NAMESPACE@, then this specification can
--     include any number of contiguous namespace strings, and can include
--     the entire label namespace prefix from the rule group or web ACL
--     where the label originates.
--
-- Labels are case sensitive and components of a label must be separated by
-- colon, for example @NS1:NS2:name@.
newLabelMatchStatement ::
  -- | 'scope'
  LabelMatchScope ->
  -- | 'key'
  Prelude.Text ->
  LabelMatchStatement
newLabelMatchStatement :: LabelMatchScope -> Text -> LabelMatchStatement
newLabelMatchStatement LabelMatchScope
pScope_ Text
pKey_ =
  LabelMatchStatement' {$sel:scope:LabelMatchStatement' :: LabelMatchScope
scope = LabelMatchScope
pScope_, $sel:key:LabelMatchStatement' :: Text
key = Text
pKey_}

-- | Specify whether you want to match using the label name or just the
-- namespace.
labelMatchStatement_scope :: Lens.Lens' LabelMatchStatement LabelMatchScope
labelMatchStatement_scope :: Lens' LabelMatchStatement LabelMatchScope
labelMatchStatement_scope = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LabelMatchStatement' {LabelMatchScope
scope :: LabelMatchScope
$sel:scope:LabelMatchStatement' :: LabelMatchStatement -> LabelMatchScope
scope} -> LabelMatchScope
scope) (\s :: LabelMatchStatement
s@LabelMatchStatement' {} LabelMatchScope
a -> LabelMatchStatement
s {$sel:scope:LabelMatchStatement' :: LabelMatchScope
scope = LabelMatchScope
a} :: LabelMatchStatement)

-- | The string to match against. The setting you provide for this depends on
-- the match statement\'s @Scope@ setting:
--
-- -   If the @Scope@ indicates @LABEL@, then this specification must
--     include the name and can include any number of preceding namespace
--     specifications and prefix up to providing the fully qualified label
--     name.
--
-- -   If the @Scope@ indicates @NAMESPACE@, then this specification can
--     include any number of contiguous namespace strings, and can include
--     the entire label namespace prefix from the rule group or web ACL
--     where the label originates.
--
-- Labels are case sensitive and components of a label must be separated by
-- colon, for example @NS1:NS2:name@.
labelMatchStatement_key :: Lens.Lens' LabelMatchStatement Prelude.Text
labelMatchStatement_key :: Lens' LabelMatchStatement Text
labelMatchStatement_key = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\LabelMatchStatement' {Text
key :: Text
$sel:key:LabelMatchStatement' :: LabelMatchStatement -> Text
key} -> Text
key) (\s :: LabelMatchStatement
s@LabelMatchStatement' {} Text
a -> LabelMatchStatement
s {$sel:key:LabelMatchStatement' :: Text
key = Text
a} :: LabelMatchStatement)

instance Data.FromJSON LabelMatchStatement where
  parseJSON :: Value -> Parser LabelMatchStatement
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"LabelMatchStatement"
      ( \Object
x ->
          LabelMatchScope -> Text -> LabelMatchStatement
LabelMatchStatement'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Scope")
            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
"Key")
      )

instance Prelude.Hashable LabelMatchStatement where
  hashWithSalt :: Int -> LabelMatchStatement -> Int
hashWithSalt Int
_salt LabelMatchStatement' {Text
LabelMatchScope
key :: Text
scope :: LabelMatchScope
$sel:key:LabelMatchStatement' :: LabelMatchStatement -> Text
$sel:scope:LabelMatchStatement' :: LabelMatchStatement -> LabelMatchScope
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` LabelMatchScope
scope
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
key

instance Prelude.NFData LabelMatchStatement where
  rnf :: LabelMatchStatement -> ()
rnf LabelMatchStatement' {Text
LabelMatchScope
key :: Text
scope :: LabelMatchScope
$sel:key:LabelMatchStatement' :: LabelMatchStatement -> Text
$sel:scope:LabelMatchStatement' :: LabelMatchStatement -> LabelMatchScope
..} =
    forall a. NFData a => a -> ()
Prelude.rnf LabelMatchScope
scope seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
key

instance Data.ToJSON LabelMatchStatement where
  toJSON :: LabelMatchStatement -> Value
toJSON LabelMatchStatement' {Text
LabelMatchScope
key :: Text
scope :: LabelMatchScope
$sel:key:LabelMatchStatement' :: LabelMatchStatement -> Text
$sel:scope:LabelMatchStatement' :: LabelMatchStatement -> LabelMatchScope
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"Scope" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= LabelMatchScope
scope),
            forall a. a -> Maybe a
Prelude.Just (Key
"Key" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
key)
          ]
      )