{-# 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.CookieMatchPattern
-- 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.CookieMatchPattern 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.All

-- | The filter to use to identify the subset of cookies to inspect in a web
-- request.
--
-- You must specify exactly one setting: either @All@, @IncludedCookies@,
-- or @ExcludedCookies@.
--
-- Example JSON:
-- @\"MatchPattern\": { \"IncludedCookies\": {\"KeyToInclude1\", \"KeyToInclude2\", \"KeyToInclude3\"} }@
--
-- /See:/ 'newCookieMatchPattern' smart constructor.
data CookieMatchPattern = CookieMatchPattern'
  { -- | Inspect all cookies.
    CookieMatchPattern -> Maybe All
all :: Prelude.Maybe All,
    -- | Inspect only the cookies whose keys don\'t match any of the strings
    -- specified here.
    CookieMatchPattern -> Maybe (NonEmpty Text)
excludedCookies :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text),
    -- | Inspect only the cookies that have a key that matches one of the strings
    -- specified here.
    CookieMatchPattern -> Maybe (NonEmpty Text)
includedCookies :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text)
  }
  deriving (CookieMatchPattern -> CookieMatchPattern -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CookieMatchPattern -> CookieMatchPattern -> Bool
$c/= :: CookieMatchPattern -> CookieMatchPattern -> Bool
== :: CookieMatchPattern -> CookieMatchPattern -> Bool
$c== :: CookieMatchPattern -> CookieMatchPattern -> Bool
Prelude.Eq, ReadPrec [CookieMatchPattern]
ReadPrec CookieMatchPattern
Int -> ReadS CookieMatchPattern
ReadS [CookieMatchPattern]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CookieMatchPattern]
$creadListPrec :: ReadPrec [CookieMatchPattern]
readPrec :: ReadPrec CookieMatchPattern
$creadPrec :: ReadPrec CookieMatchPattern
readList :: ReadS [CookieMatchPattern]
$creadList :: ReadS [CookieMatchPattern]
readsPrec :: Int -> ReadS CookieMatchPattern
$creadsPrec :: Int -> ReadS CookieMatchPattern
Prelude.Read, Int -> CookieMatchPattern -> ShowS
[CookieMatchPattern] -> ShowS
CookieMatchPattern -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CookieMatchPattern] -> ShowS
$cshowList :: [CookieMatchPattern] -> ShowS
show :: CookieMatchPattern -> String
$cshow :: CookieMatchPattern -> String
showsPrec :: Int -> CookieMatchPattern -> ShowS
$cshowsPrec :: Int -> CookieMatchPattern -> ShowS
Prelude.Show, forall x. Rep CookieMatchPattern x -> CookieMatchPattern
forall x. CookieMatchPattern -> Rep CookieMatchPattern x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CookieMatchPattern x -> CookieMatchPattern
$cfrom :: forall x. CookieMatchPattern -> Rep CookieMatchPattern x
Prelude.Generic)

-- |
-- Create a value of 'CookieMatchPattern' 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:
--
-- 'all', 'cookieMatchPattern_all' - Inspect all cookies.
--
-- 'excludedCookies', 'cookieMatchPattern_excludedCookies' - Inspect only the cookies whose keys don\'t match any of the strings
-- specified here.
--
-- 'includedCookies', 'cookieMatchPattern_includedCookies' - Inspect only the cookies that have a key that matches one of the strings
-- specified here.
newCookieMatchPattern ::
  CookieMatchPattern
newCookieMatchPattern :: CookieMatchPattern
newCookieMatchPattern =
  CookieMatchPattern'
    { $sel:all:CookieMatchPattern' :: Maybe All
all = forall a. Maybe a
Prelude.Nothing,
      $sel:excludedCookies:CookieMatchPattern' :: Maybe (NonEmpty Text)
excludedCookies = forall a. Maybe a
Prelude.Nothing,
      $sel:includedCookies:CookieMatchPattern' :: Maybe (NonEmpty Text)
includedCookies = forall a. Maybe a
Prelude.Nothing
    }

-- | Inspect all cookies.
cookieMatchPattern_all :: Lens.Lens' CookieMatchPattern (Prelude.Maybe All)
cookieMatchPattern_all :: Lens' CookieMatchPattern (Maybe All)
cookieMatchPattern_all = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CookieMatchPattern' {Maybe All
all :: Maybe All
$sel:all:CookieMatchPattern' :: CookieMatchPattern -> Maybe All
all} -> Maybe All
all) (\s :: CookieMatchPattern
s@CookieMatchPattern' {} Maybe All
a -> CookieMatchPattern
s {$sel:all:CookieMatchPattern' :: Maybe All
all = Maybe All
a} :: CookieMatchPattern)

-- | Inspect only the cookies whose keys don\'t match any of the strings
-- specified here.
cookieMatchPattern_excludedCookies :: Lens.Lens' CookieMatchPattern (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
cookieMatchPattern_excludedCookies :: Lens' CookieMatchPattern (Maybe (NonEmpty Text))
cookieMatchPattern_excludedCookies = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CookieMatchPattern' {Maybe (NonEmpty Text)
excludedCookies :: Maybe (NonEmpty Text)
$sel:excludedCookies:CookieMatchPattern' :: CookieMatchPattern -> Maybe (NonEmpty Text)
excludedCookies} -> Maybe (NonEmpty Text)
excludedCookies) (\s :: CookieMatchPattern
s@CookieMatchPattern' {} Maybe (NonEmpty Text)
a -> CookieMatchPattern
s {$sel:excludedCookies:CookieMatchPattern' :: Maybe (NonEmpty Text)
excludedCookies = Maybe (NonEmpty Text)
a} :: CookieMatchPattern) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Inspect only the cookies that have a key that matches one of the strings
-- specified here.
cookieMatchPattern_includedCookies :: Lens.Lens' CookieMatchPattern (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
cookieMatchPattern_includedCookies :: Lens' CookieMatchPattern (Maybe (NonEmpty Text))
cookieMatchPattern_includedCookies = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CookieMatchPattern' {Maybe (NonEmpty Text)
includedCookies :: Maybe (NonEmpty Text)
$sel:includedCookies:CookieMatchPattern' :: CookieMatchPattern -> Maybe (NonEmpty Text)
includedCookies} -> Maybe (NonEmpty Text)
includedCookies) (\s :: CookieMatchPattern
s@CookieMatchPattern' {} Maybe (NonEmpty Text)
a -> CookieMatchPattern
s {$sel:includedCookies:CookieMatchPattern' :: Maybe (NonEmpty Text)
includedCookies = Maybe (NonEmpty Text)
a} :: CookieMatchPattern) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON CookieMatchPattern where
  parseJSON :: Value -> Parser CookieMatchPattern
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"CookieMatchPattern"
      ( \Object
x ->
          Maybe All
-> Maybe (NonEmpty Text)
-> Maybe (NonEmpty Text)
-> CookieMatchPattern
CookieMatchPattern'
            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
"All")
            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
"ExcludedCookies")
            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
"IncludedCookies")
      )

instance Prelude.Hashable CookieMatchPattern where
  hashWithSalt :: Int -> CookieMatchPattern -> Int
hashWithSalt Int
_salt CookieMatchPattern' {Maybe (NonEmpty Text)
Maybe All
includedCookies :: Maybe (NonEmpty Text)
excludedCookies :: Maybe (NonEmpty Text)
all :: Maybe All
$sel:includedCookies:CookieMatchPattern' :: CookieMatchPattern -> Maybe (NonEmpty Text)
$sel:excludedCookies:CookieMatchPattern' :: CookieMatchPattern -> Maybe (NonEmpty Text)
$sel:all:CookieMatchPattern' :: CookieMatchPattern -> Maybe All
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe All
all
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty Text)
excludedCookies
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty Text)
includedCookies

instance Prelude.NFData CookieMatchPattern where
  rnf :: CookieMatchPattern -> ()
rnf CookieMatchPattern' {Maybe (NonEmpty Text)
Maybe All
includedCookies :: Maybe (NonEmpty Text)
excludedCookies :: Maybe (NonEmpty Text)
all :: Maybe All
$sel:includedCookies:CookieMatchPattern' :: CookieMatchPattern -> Maybe (NonEmpty Text)
$sel:excludedCookies:CookieMatchPattern' :: CookieMatchPattern -> Maybe (NonEmpty Text)
$sel:all:CookieMatchPattern' :: CookieMatchPattern -> Maybe All
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe All
all
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty Text)
excludedCookies
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty Text)
includedCookies

instance Data.ToJSON CookieMatchPattern where
  toJSON :: CookieMatchPattern -> Value
toJSON CookieMatchPattern' {Maybe (NonEmpty Text)
Maybe All
includedCookies :: Maybe (NonEmpty Text)
excludedCookies :: Maybe (NonEmpty Text)
all :: Maybe All
$sel:includedCookies:CookieMatchPattern' :: CookieMatchPattern -> Maybe (NonEmpty Text)
$sel:excludedCookies:CookieMatchPattern' :: CookieMatchPattern -> Maybe (NonEmpty Text)
$sel:all:CookieMatchPattern' :: CookieMatchPattern -> Maybe All
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"All" 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 All
all,
            (Key
"ExcludedCookies" 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 (NonEmpty Text)
excludedCookies,
            (Key
"IncludedCookies" 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 (NonEmpty Text)
includedCookies
          ]
      )