{-# 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.IoT.Types.MetricDimension
-- 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.IoT.Types.MetricDimension where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IoT.Types.DimensionValueOperator
import qualified Amazonka.Prelude as Prelude

-- | The dimension of a metric.
--
-- /See:/ 'newMetricDimension' smart constructor.
data MetricDimension = MetricDimension'
  { -- | Defines how the @dimensionValues@ of a dimension are interpreted. For
    -- example, for dimension type TOPIC_FILTER, the @IN@ operator, a message
    -- will be counted only if its topic matches one of the topic filters. With
    -- @NOT_IN@ operator, a message will be counted only if it doesn\'t match
    -- any of the topic filters. The operator is optional: if it\'s not
    -- provided (is @null@), it will be interpreted as @IN@.
    MetricDimension -> Maybe DimensionValueOperator
operator :: Prelude.Maybe DimensionValueOperator,
    -- | A unique identifier for the dimension.
    MetricDimension -> Text
dimensionName :: Prelude.Text
  }
  deriving (MetricDimension -> MetricDimension -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MetricDimension -> MetricDimension -> Bool
$c/= :: MetricDimension -> MetricDimension -> Bool
== :: MetricDimension -> MetricDimension -> Bool
$c== :: MetricDimension -> MetricDimension -> Bool
Prelude.Eq, ReadPrec [MetricDimension]
ReadPrec MetricDimension
Int -> ReadS MetricDimension
ReadS [MetricDimension]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MetricDimension]
$creadListPrec :: ReadPrec [MetricDimension]
readPrec :: ReadPrec MetricDimension
$creadPrec :: ReadPrec MetricDimension
readList :: ReadS [MetricDimension]
$creadList :: ReadS [MetricDimension]
readsPrec :: Int -> ReadS MetricDimension
$creadsPrec :: Int -> ReadS MetricDimension
Prelude.Read, Int -> MetricDimension -> ShowS
[MetricDimension] -> ShowS
MetricDimension -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MetricDimension] -> ShowS
$cshowList :: [MetricDimension] -> ShowS
show :: MetricDimension -> String
$cshow :: MetricDimension -> String
showsPrec :: Int -> MetricDimension -> ShowS
$cshowsPrec :: Int -> MetricDimension -> ShowS
Prelude.Show, forall x. Rep MetricDimension x -> MetricDimension
forall x. MetricDimension -> Rep MetricDimension x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MetricDimension x -> MetricDimension
$cfrom :: forall x. MetricDimension -> Rep MetricDimension x
Prelude.Generic)

-- |
-- Create a value of 'MetricDimension' 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:
--
-- 'operator', 'metricDimension_operator' - Defines how the @dimensionValues@ of a dimension are interpreted. For
-- example, for dimension type TOPIC_FILTER, the @IN@ operator, a message
-- will be counted only if its topic matches one of the topic filters. With
-- @NOT_IN@ operator, a message will be counted only if it doesn\'t match
-- any of the topic filters. The operator is optional: if it\'s not
-- provided (is @null@), it will be interpreted as @IN@.
--
-- 'dimensionName', 'metricDimension_dimensionName' - A unique identifier for the dimension.
newMetricDimension ::
  -- | 'dimensionName'
  Prelude.Text ->
  MetricDimension
newMetricDimension :: Text -> MetricDimension
newMetricDimension Text
pDimensionName_ =
  MetricDimension'
    { $sel:operator:MetricDimension' :: Maybe DimensionValueOperator
operator = forall a. Maybe a
Prelude.Nothing,
      $sel:dimensionName:MetricDimension' :: Text
dimensionName = Text
pDimensionName_
    }

-- | Defines how the @dimensionValues@ of a dimension are interpreted. For
-- example, for dimension type TOPIC_FILTER, the @IN@ operator, a message
-- will be counted only if its topic matches one of the topic filters. With
-- @NOT_IN@ operator, a message will be counted only if it doesn\'t match
-- any of the topic filters. The operator is optional: if it\'s not
-- provided (is @null@), it will be interpreted as @IN@.
metricDimension_operator :: Lens.Lens' MetricDimension (Prelude.Maybe DimensionValueOperator)
metricDimension_operator :: Lens' MetricDimension (Maybe DimensionValueOperator)
metricDimension_operator = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricDimension' {Maybe DimensionValueOperator
operator :: Maybe DimensionValueOperator
$sel:operator:MetricDimension' :: MetricDimension -> Maybe DimensionValueOperator
operator} -> Maybe DimensionValueOperator
operator) (\s :: MetricDimension
s@MetricDimension' {} Maybe DimensionValueOperator
a -> MetricDimension
s {$sel:operator:MetricDimension' :: Maybe DimensionValueOperator
operator = Maybe DimensionValueOperator
a} :: MetricDimension)

-- | A unique identifier for the dimension.
metricDimension_dimensionName :: Lens.Lens' MetricDimension Prelude.Text
metricDimension_dimensionName :: Lens' MetricDimension Text
metricDimension_dimensionName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricDimension' {Text
dimensionName :: Text
$sel:dimensionName:MetricDimension' :: MetricDimension -> Text
dimensionName} -> Text
dimensionName) (\s :: MetricDimension
s@MetricDimension' {} Text
a -> MetricDimension
s {$sel:dimensionName:MetricDimension' :: Text
dimensionName = Text
a} :: MetricDimension)

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

instance Prelude.Hashable MetricDimension where
  hashWithSalt :: Int -> MetricDimension -> Int
hashWithSalt Int
_salt MetricDimension' {Maybe DimensionValueOperator
Text
dimensionName :: Text
operator :: Maybe DimensionValueOperator
$sel:dimensionName:MetricDimension' :: MetricDimension -> Text
$sel:operator:MetricDimension' :: MetricDimension -> Maybe DimensionValueOperator
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe DimensionValueOperator
operator
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
dimensionName

instance Prelude.NFData MetricDimension where
  rnf :: MetricDimension -> ()
rnf MetricDimension' {Maybe DimensionValueOperator
Text
dimensionName :: Text
operator :: Maybe DimensionValueOperator
$sel:dimensionName:MetricDimension' :: MetricDimension -> Text
$sel:operator:MetricDimension' :: MetricDimension -> Maybe DimensionValueOperator
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe DimensionValueOperator
operator
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
dimensionName

instance Data.ToJSON MetricDimension where
  toJSON :: MetricDimension -> Value
toJSON MetricDimension' {Maybe DimensionValueOperator
Text
dimensionName :: Text
operator :: Maybe DimensionValueOperator
$sel:dimensionName:MetricDimension' :: MetricDimension -> Text
$sel:operator:MetricDimension' :: MetricDimension -> Maybe DimensionValueOperator
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"operator" 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 DimensionValueOperator
operator,
            forall a. a -> Maybe a
Prelude.Just
              (Key
"dimensionName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
dimensionName)
          ]
      )