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

-- | A custom action to use in stateless rule actions settings. This is used
-- in CustomAction.
--
-- /See:/ 'newActionDefinition' smart constructor.
data ActionDefinition = ActionDefinition'
  { -- | Stateless inspection criteria that publishes the specified metrics to
    -- Amazon CloudWatch for the matching packet. This setting defines a
    -- CloudWatch dimension value to be published.
    --
    -- You can pair this custom action with any of the standard stateless rule
    -- actions. For example, you could pair this in a rule action with the
    -- standard action that forwards the packet for stateful inspection. Then,
    -- when a packet matches the rule, Network Firewall publishes metrics for
    -- the packet and forwards it.
    ActionDefinition -> Maybe PublishMetricAction
publishMetricAction :: Prelude.Maybe PublishMetricAction
  }
  deriving (ActionDefinition -> ActionDefinition -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ActionDefinition -> ActionDefinition -> Bool
$c/= :: ActionDefinition -> ActionDefinition -> Bool
== :: ActionDefinition -> ActionDefinition -> Bool
$c== :: ActionDefinition -> ActionDefinition -> Bool
Prelude.Eq, ReadPrec [ActionDefinition]
ReadPrec ActionDefinition
Int -> ReadS ActionDefinition
ReadS [ActionDefinition]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ActionDefinition]
$creadListPrec :: ReadPrec [ActionDefinition]
readPrec :: ReadPrec ActionDefinition
$creadPrec :: ReadPrec ActionDefinition
readList :: ReadS [ActionDefinition]
$creadList :: ReadS [ActionDefinition]
readsPrec :: Int -> ReadS ActionDefinition
$creadsPrec :: Int -> ReadS ActionDefinition
Prelude.Read, Int -> ActionDefinition -> ShowS
[ActionDefinition] -> ShowS
ActionDefinition -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ActionDefinition] -> ShowS
$cshowList :: [ActionDefinition] -> ShowS
show :: ActionDefinition -> String
$cshow :: ActionDefinition -> String
showsPrec :: Int -> ActionDefinition -> ShowS
$cshowsPrec :: Int -> ActionDefinition -> ShowS
Prelude.Show, forall x. Rep ActionDefinition x -> ActionDefinition
forall x. ActionDefinition -> Rep ActionDefinition x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ActionDefinition x -> ActionDefinition
$cfrom :: forall x. ActionDefinition -> Rep ActionDefinition x
Prelude.Generic)

-- |
-- Create a value of 'ActionDefinition' 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:
--
-- 'publishMetricAction', 'actionDefinition_publishMetricAction' - Stateless inspection criteria that publishes the specified metrics to
-- Amazon CloudWatch for the matching packet. This setting defines a
-- CloudWatch dimension value to be published.
--
-- You can pair this custom action with any of the standard stateless rule
-- actions. For example, you could pair this in a rule action with the
-- standard action that forwards the packet for stateful inspection. Then,
-- when a packet matches the rule, Network Firewall publishes metrics for
-- the packet and forwards it.
newActionDefinition ::
  ActionDefinition
newActionDefinition :: ActionDefinition
newActionDefinition =
  ActionDefinition'
    { $sel:publishMetricAction:ActionDefinition' :: Maybe PublishMetricAction
publishMetricAction =
        forall a. Maybe a
Prelude.Nothing
    }

-- | Stateless inspection criteria that publishes the specified metrics to
-- Amazon CloudWatch for the matching packet. This setting defines a
-- CloudWatch dimension value to be published.
--
-- You can pair this custom action with any of the standard stateless rule
-- actions. For example, you could pair this in a rule action with the
-- standard action that forwards the packet for stateful inspection. Then,
-- when a packet matches the rule, Network Firewall publishes metrics for
-- the packet and forwards it.
actionDefinition_publishMetricAction :: Lens.Lens' ActionDefinition (Prelude.Maybe PublishMetricAction)
actionDefinition_publishMetricAction :: Lens' ActionDefinition (Maybe PublishMetricAction)
actionDefinition_publishMetricAction = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ActionDefinition' {Maybe PublishMetricAction
publishMetricAction :: Maybe PublishMetricAction
$sel:publishMetricAction:ActionDefinition' :: ActionDefinition -> Maybe PublishMetricAction
publishMetricAction} -> Maybe PublishMetricAction
publishMetricAction) (\s :: ActionDefinition
s@ActionDefinition' {} Maybe PublishMetricAction
a -> ActionDefinition
s {$sel:publishMetricAction:ActionDefinition' :: Maybe PublishMetricAction
publishMetricAction = Maybe PublishMetricAction
a} :: ActionDefinition)

instance Data.FromJSON ActionDefinition where
  parseJSON :: Value -> Parser ActionDefinition
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"ActionDefinition"
      ( \Object
x ->
          Maybe PublishMetricAction -> ActionDefinition
ActionDefinition'
            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
"PublishMetricAction")
      )

instance Prelude.Hashable ActionDefinition where
  hashWithSalt :: Int -> ActionDefinition -> Int
hashWithSalt Int
_salt ActionDefinition' {Maybe PublishMetricAction
publishMetricAction :: Maybe PublishMetricAction
$sel:publishMetricAction:ActionDefinition' :: ActionDefinition -> Maybe PublishMetricAction
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe PublishMetricAction
publishMetricAction

instance Prelude.NFData ActionDefinition where
  rnf :: ActionDefinition -> ()
rnf ActionDefinition' {Maybe PublishMetricAction
publishMetricAction :: Maybe PublishMetricAction
$sel:publishMetricAction:ActionDefinition' :: ActionDefinition -> Maybe PublishMetricAction
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe PublishMetricAction
publishMetricAction

instance Data.ToJSON ActionDefinition where
  toJSON :: ActionDefinition -> Value
toJSON ActionDefinition' {Maybe PublishMetricAction
publishMetricAction :: Maybe PublishMetricAction
$sel:publishMetricAction:ActionDefinition' :: ActionDefinition -> Maybe PublishMetricAction
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"PublishMetricAction" 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 PublishMetricAction
publishMetricAction
          ]
      )