{-# 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.AndStatement
-- 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.AndStatement 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 {-# SOURCE #-} Amazonka.WAFV2.Types.Statement

-- | A logical rule statement used to combine other rule statements with AND
-- logic. You provide more than one Statement within the @AndStatement@.
--
-- /See:/ 'newAndStatement' smart constructor.
data AndStatement = AndStatement'
  { -- | The statements to combine with AND logic. You can use any statements
    -- that can be nested.
    AndStatement -> [Statement]
statements :: [Statement]
  }
  deriving (AndStatement -> AndStatement -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AndStatement -> AndStatement -> Bool
$c/= :: AndStatement -> AndStatement -> Bool
== :: AndStatement -> AndStatement -> Bool
$c== :: AndStatement -> AndStatement -> Bool
Prelude.Eq, ReadPrec [AndStatement]
ReadPrec AndStatement
Int -> ReadS AndStatement
ReadS [AndStatement]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AndStatement]
$creadListPrec :: ReadPrec [AndStatement]
readPrec :: ReadPrec AndStatement
$creadPrec :: ReadPrec AndStatement
readList :: ReadS [AndStatement]
$creadList :: ReadS [AndStatement]
readsPrec :: Int -> ReadS AndStatement
$creadsPrec :: Int -> ReadS AndStatement
Prelude.Read, Int -> AndStatement -> ShowS
[AndStatement] -> ShowS
AndStatement -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AndStatement] -> ShowS
$cshowList :: [AndStatement] -> ShowS
show :: AndStatement -> String
$cshow :: AndStatement -> String
showsPrec :: Int -> AndStatement -> ShowS
$cshowsPrec :: Int -> AndStatement -> ShowS
Prelude.Show, forall x. Rep AndStatement x -> AndStatement
forall x. AndStatement -> Rep AndStatement x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AndStatement x -> AndStatement
$cfrom :: forall x. AndStatement -> Rep AndStatement x
Prelude.Generic)

-- |
-- Create a value of 'AndStatement' 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:
--
-- 'statements', 'andStatement_statements' - The statements to combine with AND logic. You can use any statements
-- that can be nested.
newAndStatement ::
  AndStatement
newAndStatement :: AndStatement
newAndStatement =
  AndStatement' {$sel:statements:AndStatement' :: [Statement]
statements = forall a. Monoid a => a
Prelude.mempty}

-- | The statements to combine with AND logic. You can use any statements
-- that can be nested.
andStatement_statements :: Lens.Lens' AndStatement [Statement]
andStatement_statements :: Lens' AndStatement [Statement]
andStatement_statements = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AndStatement' {[Statement]
statements :: [Statement]
$sel:statements:AndStatement' :: AndStatement -> [Statement]
statements} -> [Statement]
statements) (\s :: AndStatement
s@AndStatement' {} [Statement]
a -> AndStatement
s {$sel:statements:AndStatement' :: [Statement]
statements = [Statement]
a} :: AndStatement) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON AndStatement where
  parseJSON :: Value -> Parser AndStatement
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"AndStatement"
      ( \Object
x ->
          [Statement] -> AndStatement
AndStatement'
            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
"Statements" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable AndStatement where
  hashWithSalt :: Int -> AndStatement -> Int
hashWithSalt Int
_salt AndStatement' {[Statement]
statements :: [Statement]
$sel:statements:AndStatement' :: AndStatement -> [Statement]
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [Statement]
statements

instance Prelude.NFData AndStatement where
  rnf :: AndStatement -> ()
rnf AndStatement' {[Statement]
statements :: [Statement]
$sel:statements:AndStatement' :: AndStatement -> [Statement]
..} = forall a. NFData a => a -> ()
Prelude.rnf [Statement]
statements

instance Data.ToJSON AndStatement where
  toJSON :: AndStatement -> Value
toJSON AndStatement' {[Statement]
statements :: [Statement]
$sel:statements:AndStatement' :: AndStatement -> [Statement]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [forall a. a -> Maybe a
Prelude.Just (Key
"Statements" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [Statement]
statements)]
      )