{-# 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.NetworkFirewall.Types.StatelessRulesAndCustomActions
-- 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.NetworkFirewall.Types.StatelessRulesAndCustomActions where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.NetworkFirewall.Types.CustomAction
import Amazonka.NetworkFirewall.Types.StatelessRule
import qualified Amazonka.Prelude as Prelude

-- | Stateless inspection criteria. Each stateless rule group uses exactly
-- one of these data types to define its stateless rules.
--
-- /See:/ 'newStatelessRulesAndCustomActions' smart constructor.
data StatelessRulesAndCustomActions = StatelessRulesAndCustomActions'
  { -- | Defines an array of individual custom action definitions that are
    -- available for use by the stateless rules in this
    -- @StatelessRulesAndCustomActions@ specification. You name each custom
    -- action that you define, and then you can use it by name in your
    -- StatelessRule RuleDefinition @Actions@ specification.
    StatelessRulesAndCustomActions -> Maybe [CustomAction]
customActions :: Prelude.Maybe [CustomAction],
    -- | Defines the set of stateless rules for use in a stateless rule group.
    StatelessRulesAndCustomActions -> [StatelessRule]
statelessRules :: [StatelessRule]
  }
  deriving (StatelessRulesAndCustomActions
-> StatelessRulesAndCustomActions -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StatelessRulesAndCustomActions
-> StatelessRulesAndCustomActions -> Bool
$c/= :: StatelessRulesAndCustomActions
-> StatelessRulesAndCustomActions -> Bool
== :: StatelessRulesAndCustomActions
-> StatelessRulesAndCustomActions -> Bool
$c== :: StatelessRulesAndCustomActions
-> StatelessRulesAndCustomActions -> Bool
Prelude.Eq, ReadPrec [StatelessRulesAndCustomActions]
ReadPrec StatelessRulesAndCustomActions
Int -> ReadS StatelessRulesAndCustomActions
ReadS [StatelessRulesAndCustomActions]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StatelessRulesAndCustomActions]
$creadListPrec :: ReadPrec [StatelessRulesAndCustomActions]
readPrec :: ReadPrec StatelessRulesAndCustomActions
$creadPrec :: ReadPrec StatelessRulesAndCustomActions
readList :: ReadS [StatelessRulesAndCustomActions]
$creadList :: ReadS [StatelessRulesAndCustomActions]
readsPrec :: Int -> ReadS StatelessRulesAndCustomActions
$creadsPrec :: Int -> ReadS StatelessRulesAndCustomActions
Prelude.Read, Int -> StatelessRulesAndCustomActions -> ShowS
[StatelessRulesAndCustomActions] -> ShowS
StatelessRulesAndCustomActions -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StatelessRulesAndCustomActions] -> ShowS
$cshowList :: [StatelessRulesAndCustomActions] -> ShowS
show :: StatelessRulesAndCustomActions -> String
$cshow :: StatelessRulesAndCustomActions -> String
showsPrec :: Int -> StatelessRulesAndCustomActions -> ShowS
$cshowsPrec :: Int -> StatelessRulesAndCustomActions -> ShowS
Prelude.Show, forall x.
Rep StatelessRulesAndCustomActions x
-> StatelessRulesAndCustomActions
forall x.
StatelessRulesAndCustomActions
-> Rep StatelessRulesAndCustomActions x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep StatelessRulesAndCustomActions x
-> StatelessRulesAndCustomActions
$cfrom :: forall x.
StatelessRulesAndCustomActions
-> Rep StatelessRulesAndCustomActions x
Prelude.Generic)

-- |
-- Create a value of 'StatelessRulesAndCustomActions' 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:
--
-- 'customActions', 'statelessRulesAndCustomActions_customActions' - Defines an array of individual custom action definitions that are
-- available for use by the stateless rules in this
-- @StatelessRulesAndCustomActions@ specification. You name each custom
-- action that you define, and then you can use it by name in your
-- StatelessRule RuleDefinition @Actions@ specification.
--
-- 'statelessRules', 'statelessRulesAndCustomActions_statelessRules' - Defines the set of stateless rules for use in a stateless rule group.
newStatelessRulesAndCustomActions ::
  StatelessRulesAndCustomActions
newStatelessRulesAndCustomActions :: StatelessRulesAndCustomActions
newStatelessRulesAndCustomActions =
  StatelessRulesAndCustomActions'
    { $sel:customActions:StatelessRulesAndCustomActions' :: Maybe [CustomAction]
customActions =
        forall a. Maybe a
Prelude.Nothing,
      $sel:statelessRules:StatelessRulesAndCustomActions' :: [StatelessRule]
statelessRules = forall a. Monoid a => a
Prelude.mempty
    }

-- | Defines an array of individual custom action definitions that are
-- available for use by the stateless rules in this
-- @StatelessRulesAndCustomActions@ specification. You name each custom
-- action that you define, and then you can use it by name in your
-- StatelessRule RuleDefinition @Actions@ specification.
statelessRulesAndCustomActions_customActions :: Lens.Lens' StatelessRulesAndCustomActions (Prelude.Maybe [CustomAction])
statelessRulesAndCustomActions_customActions :: Lens' StatelessRulesAndCustomActions (Maybe [CustomAction])
statelessRulesAndCustomActions_customActions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StatelessRulesAndCustomActions' {Maybe [CustomAction]
customActions :: Maybe [CustomAction]
$sel:customActions:StatelessRulesAndCustomActions' :: StatelessRulesAndCustomActions -> Maybe [CustomAction]
customActions} -> Maybe [CustomAction]
customActions) (\s :: StatelessRulesAndCustomActions
s@StatelessRulesAndCustomActions' {} Maybe [CustomAction]
a -> StatelessRulesAndCustomActions
s {$sel:customActions:StatelessRulesAndCustomActions' :: Maybe [CustomAction]
customActions = Maybe [CustomAction]
a} :: StatelessRulesAndCustomActions) 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

-- | Defines the set of stateless rules for use in a stateless rule group.
statelessRulesAndCustomActions_statelessRules :: Lens.Lens' StatelessRulesAndCustomActions [StatelessRule]
statelessRulesAndCustomActions_statelessRules :: Lens' StatelessRulesAndCustomActions [StatelessRule]
statelessRulesAndCustomActions_statelessRules = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\StatelessRulesAndCustomActions' {[StatelessRule]
statelessRules :: [StatelessRule]
$sel:statelessRules:StatelessRulesAndCustomActions' :: StatelessRulesAndCustomActions -> [StatelessRule]
statelessRules} -> [StatelessRule]
statelessRules) (\s :: StatelessRulesAndCustomActions
s@StatelessRulesAndCustomActions' {} [StatelessRule]
a -> StatelessRulesAndCustomActions
s {$sel:statelessRules:StatelessRulesAndCustomActions' :: [StatelessRule]
statelessRules = [StatelessRule]
a} :: StatelessRulesAndCustomActions) 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 StatelessRulesAndCustomActions where
  parseJSON :: Value -> Parser StatelessRulesAndCustomActions
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"StatelessRulesAndCustomActions"
      ( \Object
x ->
          Maybe [CustomAction]
-> [StatelessRule] -> StatelessRulesAndCustomActions
StatelessRulesAndCustomActions'
            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
"CustomActions" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            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
"StatelessRules"
                            forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty
                        )
      )

instance
  Prelude.Hashable
    StatelessRulesAndCustomActions
  where
  hashWithSalt :: Int -> StatelessRulesAndCustomActions -> Int
hashWithSalt
    Int
_salt
    StatelessRulesAndCustomActions' {[StatelessRule]
Maybe [CustomAction]
statelessRules :: [StatelessRule]
customActions :: Maybe [CustomAction]
$sel:statelessRules:StatelessRulesAndCustomActions' :: StatelessRulesAndCustomActions -> [StatelessRule]
$sel:customActions:StatelessRulesAndCustomActions' :: StatelessRulesAndCustomActions -> Maybe [CustomAction]
..} =
      Int
_salt
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [CustomAction]
customActions
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [StatelessRule]
statelessRules

instance
  Prelude.NFData
    StatelessRulesAndCustomActions
  where
  rnf :: StatelessRulesAndCustomActions -> ()
rnf StatelessRulesAndCustomActions' {[StatelessRule]
Maybe [CustomAction]
statelessRules :: [StatelessRule]
customActions :: Maybe [CustomAction]
$sel:statelessRules:StatelessRulesAndCustomActions' :: StatelessRulesAndCustomActions -> [StatelessRule]
$sel:customActions:StatelessRulesAndCustomActions' :: StatelessRulesAndCustomActions -> Maybe [CustomAction]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [CustomAction]
customActions
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [StatelessRule]
statelessRules

instance Data.ToJSON StatelessRulesAndCustomActions where
  toJSON :: StatelessRulesAndCustomActions -> Value
toJSON StatelessRulesAndCustomActions' {[StatelessRule]
Maybe [CustomAction]
statelessRules :: [StatelessRule]
customActions :: Maybe [CustomAction]
$sel:statelessRules:StatelessRulesAndCustomActions' :: StatelessRulesAndCustomActions -> [StatelessRule]
$sel:customActions:StatelessRulesAndCustomActions' :: StatelessRulesAndCustomActions -> Maybe [CustomAction]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"CustomActions" 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 [CustomAction]
customActions,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"StatelessRules" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [StatelessRule]
statelessRules)
          ]
      )