{-# 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.CustomAction
-- 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.CustomAction 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.ActionDefinition
import qualified Amazonka.Prelude as Prelude

-- | An optional, non-standard action to use for stateless packet handling.
-- You can define this in addition to the standard action that you must
-- specify.
--
-- You define and name the custom actions that you want to be able to use,
-- and then you reference them by name in your actions settings.
--
-- You can use custom actions in the following places:
--
-- -   In a rule group\'s StatelessRulesAndCustomActions specification. The
--     custom actions are available for use by name inside the
--     @StatelessRulesAndCustomActions@ where you define them. You can use
--     them for your stateless rule actions to specify what to do with a
--     packet that matches the rule\'s match attributes.
--
-- -   In a FirewallPolicy specification, in @StatelessCustomActions@. The
--     custom actions are available for use inside the policy where you
--     define them. You can use them for the policy\'s default stateless
--     actions settings to specify what to do with packets that don\'t
--     match any of the policy\'s stateless rules.
--
-- /See:/ 'newCustomAction' smart constructor.
data CustomAction = CustomAction'
  { -- | The descriptive name of the custom action. You can\'t change the name of
    -- a custom action after you create it.
    CustomAction -> Text
actionName :: Prelude.Text,
    -- | The custom action associated with the action name.
    CustomAction -> ActionDefinition
actionDefinition :: ActionDefinition
  }
  deriving (CustomAction -> CustomAction -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CustomAction -> CustomAction -> Bool
$c/= :: CustomAction -> CustomAction -> Bool
== :: CustomAction -> CustomAction -> Bool
$c== :: CustomAction -> CustomAction -> Bool
Prelude.Eq, ReadPrec [CustomAction]
ReadPrec CustomAction
Int -> ReadS CustomAction
ReadS [CustomAction]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CustomAction]
$creadListPrec :: ReadPrec [CustomAction]
readPrec :: ReadPrec CustomAction
$creadPrec :: ReadPrec CustomAction
readList :: ReadS [CustomAction]
$creadList :: ReadS [CustomAction]
readsPrec :: Int -> ReadS CustomAction
$creadsPrec :: Int -> ReadS CustomAction
Prelude.Read, Int -> CustomAction -> ShowS
[CustomAction] -> ShowS
CustomAction -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CustomAction] -> ShowS
$cshowList :: [CustomAction] -> ShowS
show :: CustomAction -> String
$cshow :: CustomAction -> String
showsPrec :: Int -> CustomAction -> ShowS
$cshowsPrec :: Int -> CustomAction -> ShowS
Prelude.Show, forall x. Rep CustomAction x -> CustomAction
forall x. CustomAction -> Rep CustomAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CustomAction x -> CustomAction
$cfrom :: forall x. CustomAction -> Rep CustomAction x
Prelude.Generic)

-- |
-- Create a value of 'CustomAction' 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:
--
-- 'actionName', 'customAction_actionName' - The descriptive name of the custom action. You can\'t change the name of
-- a custom action after you create it.
--
-- 'actionDefinition', 'customAction_actionDefinition' - The custom action associated with the action name.
newCustomAction ::
  -- | 'actionName'
  Prelude.Text ->
  -- | 'actionDefinition'
  ActionDefinition ->
  CustomAction
newCustomAction :: Text -> ActionDefinition -> CustomAction
newCustomAction Text
pActionName_ ActionDefinition
pActionDefinition_ =
  CustomAction'
    { $sel:actionName:CustomAction' :: Text
actionName = Text
pActionName_,
      $sel:actionDefinition:CustomAction' :: ActionDefinition
actionDefinition = ActionDefinition
pActionDefinition_
    }

-- | The descriptive name of the custom action. You can\'t change the name of
-- a custom action after you create it.
customAction_actionName :: Lens.Lens' CustomAction Prelude.Text
customAction_actionName :: Lens' CustomAction Text
customAction_actionName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomAction' {Text
actionName :: Text
$sel:actionName:CustomAction' :: CustomAction -> Text
actionName} -> Text
actionName) (\s :: CustomAction
s@CustomAction' {} Text
a -> CustomAction
s {$sel:actionName:CustomAction' :: Text
actionName = Text
a} :: CustomAction)

-- | The custom action associated with the action name.
customAction_actionDefinition :: Lens.Lens' CustomAction ActionDefinition
customAction_actionDefinition :: Lens' CustomAction ActionDefinition
customAction_actionDefinition = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomAction' {ActionDefinition
actionDefinition :: ActionDefinition
$sel:actionDefinition:CustomAction' :: CustomAction -> ActionDefinition
actionDefinition} -> ActionDefinition
actionDefinition) (\s :: CustomAction
s@CustomAction' {} ActionDefinition
a -> CustomAction
s {$sel:actionDefinition:CustomAction' :: ActionDefinition
actionDefinition = ActionDefinition
a} :: CustomAction)

instance Data.FromJSON CustomAction where
  parseJSON :: Value -> Parser CustomAction
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"CustomAction"
      ( \Object
x ->
          Text -> ActionDefinition -> CustomAction
CustomAction'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"ActionName")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"ActionDefinition")
      )

instance Prelude.Hashable CustomAction where
  hashWithSalt :: Int -> CustomAction -> Int
hashWithSalt Int
_salt CustomAction' {Text
ActionDefinition
actionDefinition :: ActionDefinition
actionName :: Text
$sel:actionDefinition:CustomAction' :: CustomAction -> ActionDefinition
$sel:actionName:CustomAction' :: CustomAction -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
actionName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` ActionDefinition
actionDefinition

instance Prelude.NFData CustomAction where
  rnf :: CustomAction -> ()
rnf CustomAction' {Text
ActionDefinition
actionDefinition :: ActionDefinition
actionName :: Text
$sel:actionDefinition:CustomAction' :: CustomAction -> ActionDefinition
$sel:actionName:CustomAction' :: CustomAction -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
actionName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf ActionDefinition
actionDefinition

instance Data.ToJSON CustomAction where
  toJSON :: CustomAction -> Value
toJSON CustomAction' {Text
ActionDefinition
actionDefinition :: ActionDefinition
actionName :: Text
$sel:actionDefinition:CustomAction' :: CustomAction -> ActionDefinition
$sel:actionName:CustomAction' :: CustomAction -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"ActionName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
actionName),
            forall a. a -> Maybe a
Prelude.Just
              (Key
"ActionDefinition" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= ActionDefinition
actionDefinition)
          ]
      )