{-# 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-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.NetworkFirewall.Types.StatelessRulesAndCustomActions where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(StatelessRulesAndCustomActions
 -> StatelessRulesAndCustomActions -> Bool)
-> (StatelessRulesAndCustomActions
    -> StatelessRulesAndCustomActions -> Bool)
-> Eq StatelessRulesAndCustomActions
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]
(Int -> ReadS StatelessRulesAndCustomActions)
-> ReadS [StatelessRulesAndCustomActions]
-> ReadPrec StatelessRulesAndCustomActions
-> ReadPrec [StatelessRulesAndCustomActions]
-> Read 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
(Int -> StatelessRulesAndCustomActions -> ShowS)
-> (StatelessRulesAndCustomActions -> String)
-> ([StatelessRulesAndCustomActions] -> ShowS)
-> Show StatelessRulesAndCustomActions
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.
 StatelessRulesAndCustomActions
 -> Rep StatelessRulesAndCustomActions x)
-> (forall x.
    Rep StatelessRulesAndCustomActions x
    -> StatelessRulesAndCustomActions)
-> Generic StatelessRulesAndCustomActions
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' :: Maybe [CustomAction]
-> [StatelessRule] -> StatelessRulesAndCustomActions
StatelessRulesAndCustomActions'
    { $sel:customActions:StatelessRulesAndCustomActions' :: Maybe [CustomAction]
customActions =
        Maybe [CustomAction]
forall a. Maybe a
Prelude.Nothing,
      $sel:statelessRules:StatelessRulesAndCustomActions' :: [StatelessRule]
statelessRules = [StatelessRule]
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 :: (Maybe [CustomAction] -> f (Maybe [CustomAction]))
-> StatelessRulesAndCustomActions
-> f StatelessRulesAndCustomActions
statelessRulesAndCustomActions_customActions = (StatelessRulesAndCustomActions -> Maybe [CustomAction])
-> (StatelessRulesAndCustomActions
    -> Maybe [CustomAction] -> StatelessRulesAndCustomActions)
-> Lens
     StatelessRulesAndCustomActions
     StatelessRulesAndCustomActions
     (Maybe [CustomAction])
     (Maybe [CustomAction])
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) ((Maybe [CustomAction] -> f (Maybe [CustomAction]))
 -> StatelessRulesAndCustomActions
 -> f StatelessRulesAndCustomActions)
-> ((Maybe [CustomAction] -> f (Maybe [CustomAction]))
    -> Maybe [CustomAction] -> f (Maybe [CustomAction]))
-> (Maybe [CustomAction] -> f (Maybe [CustomAction]))
-> StatelessRulesAndCustomActions
-> f StatelessRulesAndCustomActions
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [CustomAction] [CustomAction] [CustomAction] [CustomAction]
-> Iso
     (Maybe [CustomAction])
     (Maybe [CustomAction])
     (Maybe [CustomAction])
     (Maybe [CustomAction])
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 AnIso [CustomAction] [CustomAction] [CustomAction] [CustomAction]
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 :: ([StatelessRule] -> f [StatelessRule])
-> StatelessRulesAndCustomActions
-> f StatelessRulesAndCustomActions
statelessRulesAndCustomActions_statelessRules = (StatelessRulesAndCustomActions -> [StatelessRule])
-> (StatelessRulesAndCustomActions
    -> [StatelessRule] -> StatelessRulesAndCustomActions)
-> Lens
     StatelessRulesAndCustomActions
     StatelessRulesAndCustomActions
     [StatelessRule]
     [StatelessRule]
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) (([StatelessRule] -> f [StatelessRule])
 -> StatelessRulesAndCustomActions
 -> f StatelessRulesAndCustomActions)
-> (([StatelessRule] -> f [StatelessRule])
    -> [StatelessRule] -> f [StatelessRule])
-> ([StatelessRule] -> f [StatelessRule])
-> StatelessRulesAndCustomActions
-> f StatelessRulesAndCustomActions
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([StatelessRule] -> f [StatelessRule])
-> [StatelessRule] -> f [StatelessRule]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON StatelessRulesAndCustomActions where
  parseJSON :: Value -> Parser StatelessRulesAndCustomActions
parseJSON =
    String
-> (Object -> Parser StatelessRulesAndCustomActions)
-> Value
-> Parser StatelessRulesAndCustomActions
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"StatelessRulesAndCustomActions"
      ( \Object
x ->
          Maybe [CustomAction]
-> [StatelessRule] -> StatelessRulesAndCustomActions
StatelessRulesAndCustomActions'
            (Maybe [CustomAction]
 -> [StatelessRule] -> StatelessRulesAndCustomActions)
-> Parser (Maybe [CustomAction])
-> Parser ([StatelessRule] -> StatelessRulesAndCustomActions)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [CustomAction]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"CustomActions" Parser (Maybe (Maybe [CustomAction]))
-> Maybe [CustomAction] -> Parser (Maybe [CustomAction])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [CustomAction]
forall a. Monoid a => a
Prelude.mempty)
            Parser ([StatelessRule] -> StatelessRulesAndCustomActions)
-> Parser [StatelessRule] -> Parser StatelessRulesAndCustomActions
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x Object -> Text -> Parser (Maybe [StatelessRule])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"StatelessRules"
                            Parser (Maybe [StatelessRule])
-> [StatelessRule] -> Parser [StatelessRule]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [StatelessRule]
forall a. Monoid a => a
Prelude.mempty
                        )
      )

instance
  Prelude.Hashable
    StatelessRulesAndCustomActions

instance
  Prelude.NFData
    StatelessRulesAndCustomActions

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"CustomActions" Text -> [CustomAction] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([CustomAction] -> Pair) -> Maybe [CustomAction] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [CustomAction]
customActions,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"StatelessRules" Text -> [StatelessRule] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [StatelessRule]
statelessRules)
          ]
      )