{-# 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.JsonMatchPattern
-- 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.JsonMatchPattern 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 patterns to look for in the JSON body. WAF inspects the results of
-- these pattern matches against the rule inspection criteria. This is used
-- with the FieldToMatch option @JsonBody@.
--
-- /See:/ 'newJsonMatchPattern' smart constructor.
data JsonMatchPattern = JsonMatchPattern'
  { -- | Match all of the elements. See also @MatchScope@ in JsonBody.
    --
    -- You must specify either this setting or the @IncludedPaths@ setting, but
    -- not both.
    JsonMatchPattern -> Maybe All
all :: Prelude.Maybe All,
    -- | Match only the specified include paths. See also @MatchScope@ in
    -- JsonBody.
    --
    -- Provide the include paths using JSON Pointer syntax. For example,
    -- @\"IncludedPaths\": [\"\/dogs\/0\/name\", \"\/dogs\/1\/name\"]@. For
    -- information about this syntax, see the Internet Engineering Task Force
    -- (IETF) documentation
    -- <https://tools.ietf.org/html/rfc6901 JavaScript Object Notation (JSON) Pointer>.
    --
    -- You must specify either this setting or the @All@ setting, but not both.
    --
    -- Don\'t use this option to include all paths. Instead, use the @All@
    -- setting.
    JsonMatchPattern -> Maybe (NonEmpty Text)
includedPaths :: Prelude.Maybe (Prelude.NonEmpty Prelude.Text)
  }
  deriving (JsonMatchPattern -> JsonMatchPattern -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: JsonMatchPattern -> JsonMatchPattern -> Bool
$c/= :: JsonMatchPattern -> JsonMatchPattern -> Bool
== :: JsonMatchPattern -> JsonMatchPattern -> Bool
$c== :: JsonMatchPattern -> JsonMatchPattern -> Bool
Prelude.Eq, ReadPrec [JsonMatchPattern]
ReadPrec JsonMatchPattern
Int -> ReadS JsonMatchPattern
ReadS [JsonMatchPattern]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [JsonMatchPattern]
$creadListPrec :: ReadPrec [JsonMatchPattern]
readPrec :: ReadPrec JsonMatchPattern
$creadPrec :: ReadPrec JsonMatchPattern
readList :: ReadS [JsonMatchPattern]
$creadList :: ReadS [JsonMatchPattern]
readsPrec :: Int -> ReadS JsonMatchPattern
$creadsPrec :: Int -> ReadS JsonMatchPattern
Prelude.Read, Int -> JsonMatchPattern -> ShowS
[JsonMatchPattern] -> ShowS
JsonMatchPattern -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [JsonMatchPattern] -> ShowS
$cshowList :: [JsonMatchPattern] -> ShowS
show :: JsonMatchPattern -> String
$cshow :: JsonMatchPattern -> String
showsPrec :: Int -> JsonMatchPattern -> ShowS
$cshowsPrec :: Int -> JsonMatchPattern -> ShowS
Prelude.Show, forall x. Rep JsonMatchPattern x -> JsonMatchPattern
forall x. JsonMatchPattern -> Rep JsonMatchPattern x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep JsonMatchPattern x -> JsonMatchPattern
$cfrom :: forall x. JsonMatchPattern -> Rep JsonMatchPattern x
Prelude.Generic)

-- |
-- Create a value of 'JsonMatchPattern' 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', 'jsonMatchPattern_all' - Match all of the elements. See also @MatchScope@ in JsonBody.
--
-- You must specify either this setting or the @IncludedPaths@ setting, but
-- not both.
--
-- 'includedPaths', 'jsonMatchPattern_includedPaths' - Match only the specified include paths. See also @MatchScope@ in
-- JsonBody.
--
-- Provide the include paths using JSON Pointer syntax. For example,
-- @\"IncludedPaths\": [\"\/dogs\/0\/name\", \"\/dogs\/1\/name\"]@. For
-- information about this syntax, see the Internet Engineering Task Force
-- (IETF) documentation
-- <https://tools.ietf.org/html/rfc6901 JavaScript Object Notation (JSON) Pointer>.
--
-- You must specify either this setting or the @All@ setting, but not both.
--
-- Don\'t use this option to include all paths. Instead, use the @All@
-- setting.
newJsonMatchPattern ::
  JsonMatchPattern
newJsonMatchPattern :: JsonMatchPattern
newJsonMatchPattern =
  JsonMatchPattern'
    { $sel:all:JsonMatchPattern' :: Maybe All
all = forall a. Maybe a
Prelude.Nothing,
      $sel:includedPaths:JsonMatchPattern' :: Maybe (NonEmpty Text)
includedPaths = forall a. Maybe a
Prelude.Nothing
    }

-- | Match all of the elements. See also @MatchScope@ in JsonBody.
--
-- You must specify either this setting or the @IncludedPaths@ setting, but
-- not both.
jsonMatchPattern_all :: Lens.Lens' JsonMatchPattern (Prelude.Maybe All)
jsonMatchPattern_all :: Lens' JsonMatchPattern (Maybe All)
jsonMatchPattern_all = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\JsonMatchPattern' {Maybe All
all :: Maybe All
$sel:all:JsonMatchPattern' :: JsonMatchPattern -> Maybe All
all} -> Maybe All
all) (\s :: JsonMatchPattern
s@JsonMatchPattern' {} Maybe All
a -> JsonMatchPattern
s {$sel:all:JsonMatchPattern' :: Maybe All
all = Maybe All
a} :: JsonMatchPattern)

-- | Match only the specified include paths. See also @MatchScope@ in
-- JsonBody.
--
-- Provide the include paths using JSON Pointer syntax. For example,
-- @\"IncludedPaths\": [\"\/dogs\/0\/name\", \"\/dogs\/1\/name\"]@. For
-- information about this syntax, see the Internet Engineering Task Force
-- (IETF) documentation
-- <https://tools.ietf.org/html/rfc6901 JavaScript Object Notation (JSON) Pointer>.
--
-- You must specify either this setting or the @All@ setting, but not both.
--
-- Don\'t use this option to include all paths. Instead, use the @All@
-- setting.
jsonMatchPattern_includedPaths :: Lens.Lens' JsonMatchPattern (Prelude.Maybe (Prelude.NonEmpty Prelude.Text))
jsonMatchPattern_includedPaths :: Lens' JsonMatchPattern (Maybe (NonEmpty Text))
jsonMatchPattern_includedPaths = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\JsonMatchPattern' {Maybe (NonEmpty Text)
includedPaths :: Maybe (NonEmpty Text)
$sel:includedPaths:JsonMatchPattern' :: JsonMatchPattern -> Maybe (NonEmpty Text)
includedPaths} -> Maybe (NonEmpty Text)
includedPaths) (\s :: JsonMatchPattern
s@JsonMatchPattern' {} Maybe (NonEmpty Text)
a -> JsonMatchPattern
s {$sel:includedPaths:JsonMatchPattern' :: Maybe (NonEmpty Text)
includedPaths = Maybe (NonEmpty Text)
a} :: JsonMatchPattern) 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 JsonMatchPattern where
  parseJSON :: Value -> Parser JsonMatchPattern
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"JsonMatchPattern"
      ( \Object
x ->
          Maybe All -> Maybe (NonEmpty Text) -> JsonMatchPattern
JsonMatchPattern'
            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
"IncludedPaths")
      )

instance Prelude.Hashable JsonMatchPattern where
  hashWithSalt :: Int -> JsonMatchPattern -> Int
hashWithSalt Int
_salt JsonMatchPattern' {Maybe (NonEmpty Text)
Maybe All
includedPaths :: Maybe (NonEmpty Text)
all :: Maybe All
$sel:includedPaths:JsonMatchPattern' :: JsonMatchPattern -> Maybe (NonEmpty Text)
$sel:all:JsonMatchPattern' :: JsonMatchPattern -> 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)
includedPaths

instance Prelude.NFData JsonMatchPattern where
  rnf :: JsonMatchPattern -> ()
rnf JsonMatchPattern' {Maybe (NonEmpty Text)
Maybe All
includedPaths :: Maybe (NonEmpty Text)
all :: Maybe All
$sel:includedPaths:JsonMatchPattern' :: JsonMatchPattern -> Maybe (NonEmpty Text)
$sel:all:JsonMatchPattern' :: JsonMatchPattern -> 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)
includedPaths

instance Data.ToJSON JsonMatchPattern where
  toJSON :: JsonMatchPattern -> Value
toJSON JsonMatchPattern' {Maybe (NonEmpty Text)
Maybe All
includedPaths :: Maybe (NonEmpty Text)
all :: Maybe All
$sel:includedPaths:JsonMatchPattern' :: JsonMatchPattern -> Maybe (NonEmpty Text)
$sel:all:JsonMatchPattern' :: JsonMatchPattern -> 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
"IncludedPaths" 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)
includedPaths
          ]
      )