{-# 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.PublishMetricAction
-- 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.PublishMetricAction where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.NetworkFirewall.Types.Dimension
import qualified Amazonka.Prelude as Prelude

-- | 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.
--
-- /See:/ 'newPublishMetricAction' smart constructor.
data PublishMetricAction = PublishMetricAction'
  { PublishMetricAction -> NonEmpty Dimension
dimensions :: Prelude.NonEmpty Dimension
  }
  deriving (PublishMetricAction -> PublishMetricAction -> Bool
(PublishMetricAction -> PublishMetricAction -> Bool)
-> (PublishMetricAction -> PublishMetricAction -> Bool)
-> Eq PublishMetricAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PublishMetricAction -> PublishMetricAction -> Bool
$c/= :: PublishMetricAction -> PublishMetricAction -> Bool
== :: PublishMetricAction -> PublishMetricAction -> Bool
$c== :: PublishMetricAction -> PublishMetricAction -> Bool
Prelude.Eq, ReadPrec [PublishMetricAction]
ReadPrec PublishMetricAction
Int -> ReadS PublishMetricAction
ReadS [PublishMetricAction]
(Int -> ReadS PublishMetricAction)
-> ReadS [PublishMetricAction]
-> ReadPrec PublishMetricAction
-> ReadPrec [PublishMetricAction]
-> Read PublishMetricAction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PublishMetricAction]
$creadListPrec :: ReadPrec [PublishMetricAction]
readPrec :: ReadPrec PublishMetricAction
$creadPrec :: ReadPrec PublishMetricAction
readList :: ReadS [PublishMetricAction]
$creadList :: ReadS [PublishMetricAction]
readsPrec :: Int -> ReadS PublishMetricAction
$creadsPrec :: Int -> ReadS PublishMetricAction
Prelude.Read, Int -> PublishMetricAction -> ShowS
[PublishMetricAction] -> ShowS
PublishMetricAction -> String
(Int -> PublishMetricAction -> ShowS)
-> (PublishMetricAction -> String)
-> ([PublishMetricAction] -> ShowS)
-> Show PublishMetricAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PublishMetricAction] -> ShowS
$cshowList :: [PublishMetricAction] -> ShowS
show :: PublishMetricAction -> String
$cshow :: PublishMetricAction -> String
showsPrec :: Int -> PublishMetricAction -> ShowS
$cshowsPrec :: Int -> PublishMetricAction -> ShowS
Prelude.Show, (forall x. PublishMetricAction -> Rep PublishMetricAction x)
-> (forall x. Rep PublishMetricAction x -> PublishMetricAction)
-> Generic PublishMetricAction
forall x. Rep PublishMetricAction x -> PublishMetricAction
forall x. PublishMetricAction -> Rep PublishMetricAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PublishMetricAction x -> PublishMetricAction
$cfrom :: forall x. PublishMetricAction -> Rep PublishMetricAction x
Prelude.Generic)

-- |
-- Create a value of 'PublishMetricAction' 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:
--
-- 'dimensions', 'publishMetricAction_dimensions' -
newPublishMetricAction ::
  -- | 'dimensions'
  Prelude.NonEmpty Dimension ->
  PublishMetricAction
newPublishMetricAction :: NonEmpty Dimension -> PublishMetricAction
newPublishMetricAction NonEmpty Dimension
pDimensions_ =
  PublishMetricAction' :: NonEmpty Dimension -> PublishMetricAction
PublishMetricAction'
    { $sel:dimensions:PublishMetricAction' :: NonEmpty Dimension
dimensions =
        Tagged (NonEmpty Dimension) (Identity (NonEmpty Dimension))
-> Tagged (NonEmpty Dimension) (Identity (NonEmpty Dimension))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty Dimension) (Identity (NonEmpty Dimension))
 -> Tagged (NonEmpty Dimension) (Identity (NonEmpty Dimension)))
-> NonEmpty Dimension -> NonEmpty Dimension
forall t b. AReview t b -> b -> t
Lens.# NonEmpty Dimension
pDimensions_
    }

-- |
publishMetricAction_dimensions :: Lens.Lens' PublishMetricAction (Prelude.NonEmpty Dimension)
publishMetricAction_dimensions :: (NonEmpty Dimension -> f (NonEmpty Dimension))
-> PublishMetricAction -> f PublishMetricAction
publishMetricAction_dimensions = (PublishMetricAction -> NonEmpty Dimension)
-> (PublishMetricAction
    -> NonEmpty Dimension -> PublishMetricAction)
-> Lens
     PublishMetricAction
     PublishMetricAction
     (NonEmpty Dimension)
     (NonEmpty Dimension)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PublishMetricAction' {NonEmpty Dimension
dimensions :: NonEmpty Dimension
$sel:dimensions:PublishMetricAction' :: PublishMetricAction -> NonEmpty Dimension
dimensions} -> NonEmpty Dimension
dimensions) (\s :: PublishMetricAction
s@PublishMetricAction' {} NonEmpty Dimension
a -> PublishMetricAction
s {$sel:dimensions:PublishMetricAction' :: NonEmpty Dimension
dimensions = NonEmpty Dimension
a} :: PublishMetricAction) ((NonEmpty Dimension -> f (NonEmpty Dimension))
 -> PublishMetricAction -> f PublishMetricAction)
-> ((NonEmpty Dimension -> f (NonEmpty Dimension))
    -> NonEmpty Dimension -> f (NonEmpty Dimension))
-> (NonEmpty Dimension -> f (NonEmpty Dimension))
-> PublishMetricAction
-> f PublishMetricAction
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty Dimension -> f (NonEmpty Dimension))
-> NonEmpty Dimension -> f (NonEmpty Dimension)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON PublishMetricAction where
  parseJSON :: Value -> Parser PublishMetricAction
parseJSON =
    String
-> (Object -> Parser PublishMetricAction)
-> Value
-> Parser PublishMetricAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"PublishMetricAction"
      ( \Object
x ->
          NonEmpty Dimension -> PublishMetricAction
PublishMetricAction'
            (NonEmpty Dimension -> PublishMetricAction)
-> Parser (NonEmpty Dimension) -> Parser PublishMetricAction
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (NonEmpty Dimension)
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Dimensions")
      )

instance Prelude.Hashable PublishMetricAction

instance Prelude.NFData PublishMetricAction

instance Core.ToJSON PublishMetricAction where
  toJSON :: PublishMetricAction -> Value
toJSON PublishMetricAction' {NonEmpty Dimension
dimensions :: NonEmpty Dimension
$sel:dimensions:PublishMetricAction' :: PublishMetricAction -> NonEmpty Dimension
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Dimensions" Text -> NonEmpty Dimension -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty Dimension
dimensions)]
      )