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

import qualified Amazonka.Core as Core
import Amazonka.IoT.Types.MetricDimension
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The metric you want to retain. Dimensions are optional.
--
-- /See:/ 'newMetricToRetain' smart constructor.
data MetricToRetain = MetricToRetain'
  { -- | The dimension of a metric. This can\'t be used with custom metrics.
    MetricToRetain -> Maybe MetricDimension
metricDimension :: Prelude.Maybe MetricDimension,
    -- | What is measured by the behavior.
    MetricToRetain -> Text
metric :: Prelude.Text
  }
  deriving (MetricToRetain -> MetricToRetain -> Bool
(MetricToRetain -> MetricToRetain -> Bool)
-> (MetricToRetain -> MetricToRetain -> Bool) -> Eq MetricToRetain
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MetricToRetain -> MetricToRetain -> Bool
$c/= :: MetricToRetain -> MetricToRetain -> Bool
== :: MetricToRetain -> MetricToRetain -> Bool
$c== :: MetricToRetain -> MetricToRetain -> Bool
Prelude.Eq, ReadPrec [MetricToRetain]
ReadPrec MetricToRetain
Int -> ReadS MetricToRetain
ReadS [MetricToRetain]
(Int -> ReadS MetricToRetain)
-> ReadS [MetricToRetain]
-> ReadPrec MetricToRetain
-> ReadPrec [MetricToRetain]
-> Read MetricToRetain
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MetricToRetain]
$creadListPrec :: ReadPrec [MetricToRetain]
readPrec :: ReadPrec MetricToRetain
$creadPrec :: ReadPrec MetricToRetain
readList :: ReadS [MetricToRetain]
$creadList :: ReadS [MetricToRetain]
readsPrec :: Int -> ReadS MetricToRetain
$creadsPrec :: Int -> ReadS MetricToRetain
Prelude.Read, Int -> MetricToRetain -> ShowS
[MetricToRetain] -> ShowS
MetricToRetain -> String
(Int -> MetricToRetain -> ShowS)
-> (MetricToRetain -> String)
-> ([MetricToRetain] -> ShowS)
-> Show MetricToRetain
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MetricToRetain] -> ShowS
$cshowList :: [MetricToRetain] -> ShowS
show :: MetricToRetain -> String
$cshow :: MetricToRetain -> String
showsPrec :: Int -> MetricToRetain -> ShowS
$cshowsPrec :: Int -> MetricToRetain -> ShowS
Prelude.Show, (forall x. MetricToRetain -> Rep MetricToRetain x)
-> (forall x. Rep MetricToRetain x -> MetricToRetain)
-> Generic MetricToRetain
forall x. Rep MetricToRetain x -> MetricToRetain
forall x. MetricToRetain -> Rep MetricToRetain x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MetricToRetain x -> MetricToRetain
$cfrom :: forall x. MetricToRetain -> Rep MetricToRetain x
Prelude.Generic)

-- |
-- Create a value of 'MetricToRetain' 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:
--
-- 'metricDimension', 'metricToRetain_metricDimension' - The dimension of a metric. This can\'t be used with custom metrics.
--
-- 'metric', 'metricToRetain_metric' - What is measured by the behavior.
newMetricToRetain ::
  -- | 'metric'
  Prelude.Text ->
  MetricToRetain
newMetricToRetain :: Text -> MetricToRetain
newMetricToRetain Text
pMetric_ =
  MetricToRetain' :: Maybe MetricDimension -> Text -> MetricToRetain
MetricToRetain'
    { $sel:metricDimension:MetricToRetain' :: Maybe MetricDimension
metricDimension = Maybe MetricDimension
forall a. Maybe a
Prelude.Nothing,
      $sel:metric:MetricToRetain' :: Text
metric = Text
pMetric_
    }

-- | The dimension of a metric. This can\'t be used with custom metrics.
metricToRetain_metricDimension :: Lens.Lens' MetricToRetain (Prelude.Maybe MetricDimension)
metricToRetain_metricDimension :: (Maybe MetricDimension -> f (Maybe MetricDimension))
-> MetricToRetain -> f MetricToRetain
metricToRetain_metricDimension = (MetricToRetain -> Maybe MetricDimension)
-> (MetricToRetain -> Maybe MetricDimension -> MetricToRetain)
-> Lens
     MetricToRetain
     MetricToRetain
     (Maybe MetricDimension)
     (Maybe MetricDimension)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricToRetain' {Maybe MetricDimension
metricDimension :: Maybe MetricDimension
$sel:metricDimension:MetricToRetain' :: MetricToRetain -> Maybe MetricDimension
metricDimension} -> Maybe MetricDimension
metricDimension) (\s :: MetricToRetain
s@MetricToRetain' {} Maybe MetricDimension
a -> MetricToRetain
s {$sel:metricDimension:MetricToRetain' :: Maybe MetricDimension
metricDimension = Maybe MetricDimension
a} :: MetricToRetain)

-- | What is measured by the behavior.
metricToRetain_metric :: Lens.Lens' MetricToRetain Prelude.Text
metricToRetain_metric :: (Text -> f Text) -> MetricToRetain -> f MetricToRetain
metricToRetain_metric = (MetricToRetain -> Text)
-> (MetricToRetain -> Text -> MetricToRetain)
-> Lens MetricToRetain MetricToRetain Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricToRetain' {Text
metric :: Text
$sel:metric:MetricToRetain' :: MetricToRetain -> Text
metric} -> Text
metric) (\s :: MetricToRetain
s@MetricToRetain' {} Text
a -> MetricToRetain
s {$sel:metric:MetricToRetain' :: Text
metric = Text
a} :: MetricToRetain)

instance Core.FromJSON MetricToRetain where
  parseJSON :: Value -> Parser MetricToRetain
parseJSON =
    String
-> (Object -> Parser MetricToRetain)
-> Value
-> Parser MetricToRetain
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"MetricToRetain"
      ( \Object
x ->
          Maybe MetricDimension -> Text -> MetricToRetain
MetricToRetain'
            (Maybe MetricDimension -> Text -> MetricToRetain)
-> Parser (Maybe MetricDimension)
-> Parser (Text -> MetricToRetain)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe MetricDimension)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"metricDimension")
            Parser (Text -> MetricToRetain)
-> Parser Text -> Parser MetricToRetain
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"metric")
      )

instance Prelude.Hashable MetricToRetain

instance Prelude.NFData MetricToRetain

instance Core.ToJSON MetricToRetain where
  toJSON :: MetricToRetain -> Value
toJSON MetricToRetain' {Maybe MetricDimension
Text
metric :: Text
metricDimension :: Maybe MetricDimension
$sel:metric:MetricToRetain' :: MetricToRetain -> Text
$sel:metricDimension:MetricToRetain' :: MetricToRetain -> Maybe MetricDimension
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"metricDimension" Text -> MetricDimension -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (MetricDimension -> Pair) -> Maybe MetricDimension -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe MetricDimension
metricDimension,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"metric" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
metric)
          ]
      )