{-# 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 #-}
module Amazonka.LookoutMetrics.Types.Metric where
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.LookoutMetrics.Types.AggregationFunction
import qualified Amazonka.Prelude as Prelude
data Metric = Metric'
{
Metric -> Maybe Text
namespace :: Prelude.Maybe Prelude.Text,
Metric -> Text
metricName :: Prelude.Text,
Metric -> AggregationFunction
aggregationFunction :: AggregationFunction
}
deriving (Metric -> Metric -> Bool
(Metric -> Metric -> Bool)
-> (Metric -> Metric -> Bool) -> Eq Metric
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Metric -> Metric -> Bool
$c/= :: Metric -> Metric -> Bool
== :: Metric -> Metric -> Bool
$c== :: Metric -> Metric -> Bool
Prelude.Eq, ReadPrec [Metric]
ReadPrec Metric
Int -> ReadS Metric
ReadS [Metric]
(Int -> ReadS Metric)
-> ReadS [Metric]
-> ReadPrec Metric
-> ReadPrec [Metric]
-> Read Metric
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Metric]
$creadListPrec :: ReadPrec [Metric]
readPrec :: ReadPrec Metric
$creadPrec :: ReadPrec Metric
readList :: ReadS [Metric]
$creadList :: ReadS [Metric]
readsPrec :: Int -> ReadS Metric
$creadsPrec :: Int -> ReadS Metric
Prelude.Read, Int -> Metric -> ShowS
[Metric] -> ShowS
Metric -> String
(Int -> Metric -> ShowS)
-> (Metric -> String) -> ([Metric] -> ShowS) -> Show Metric
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Metric] -> ShowS
$cshowList :: [Metric] -> ShowS
show :: Metric -> String
$cshow :: Metric -> String
showsPrec :: Int -> Metric -> ShowS
$cshowsPrec :: Int -> Metric -> ShowS
Prelude.Show, (forall x. Metric -> Rep Metric x)
-> (forall x. Rep Metric x -> Metric) -> Generic Metric
forall x. Rep Metric x -> Metric
forall x. Metric -> Rep Metric x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Metric x -> Metric
$cfrom :: forall x. Metric -> Rep Metric x
Prelude.Generic)
newMetric ::
Prelude.Text ->
AggregationFunction ->
Metric
newMetric :: Text -> AggregationFunction -> Metric
newMetric Text
pMetricName_ AggregationFunction
pAggregationFunction_ =
Metric' :: Maybe Text -> Text -> AggregationFunction -> Metric
Metric'
{ $sel:namespace:Metric' :: Maybe Text
namespace = Maybe Text
forall a. Maybe a
Prelude.Nothing,
$sel:metricName:Metric' :: Text
metricName = Text
pMetricName_,
$sel:aggregationFunction:Metric' :: AggregationFunction
aggregationFunction = AggregationFunction
pAggregationFunction_
}
metric_namespace :: Lens.Lens' Metric (Prelude.Maybe Prelude.Text)
metric_namespace :: (Maybe Text -> f (Maybe Text)) -> Metric -> f Metric
metric_namespace = (Metric -> Maybe Text)
-> (Metric -> Maybe Text -> Metric)
-> Lens Metric Metric (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Metric' {Maybe Text
namespace :: Maybe Text
$sel:namespace:Metric' :: Metric -> Maybe Text
namespace} -> Maybe Text
namespace) (\s :: Metric
s@Metric' {} Maybe Text
a -> Metric
s {$sel:namespace:Metric' :: Maybe Text
namespace = Maybe Text
a} :: Metric)
metric_metricName :: Lens.Lens' Metric Prelude.Text
metric_metricName :: (Text -> f Text) -> Metric -> f Metric
metric_metricName = (Metric -> Text)
-> (Metric -> Text -> Metric) -> Lens Metric Metric Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Metric' {Text
metricName :: Text
$sel:metricName:Metric' :: Metric -> Text
metricName} -> Text
metricName) (\s :: Metric
s@Metric' {} Text
a -> Metric
s {$sel:metricName:Metric' :: Text
metricName = Text
a} :: Metric)
metric_aggregationFunction :: Lens.Lens' Metric AggregationFunction
metric_aggregationFunction :: (AggregationFunction -> f AggregationFunction)
-> Metric -> f Metric
metric_aggregationFunction = (Metric -> AggregationFunction)
-> (Metric -> AggregationFunction -> Metric)
-> Lens Metric Metric AggregationFunction AggregationFunction
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Metric' {AggregationFunction
aggregationFunction :: AggregationFunction
$sel:aggregationFunction:Metric' :: Metric -> AggregationFunction
aggregationFunction} -> AggregationFunction
aggregationFunction) (\s :: Metric
s@Metric' {} AggregationFunction
a -> Metric
s {$sel:aggregationFunction:Metric' :: AggregationFunction
aggregationFunction = AggregationFunction
a} :: Metric)
instance Core.FromJSON Metric where
parseJSON :: Value -> Parser Metric
parseJSON =
String -> (Object -> Parser Metric) -> Value -> Parser Metric
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
String
"Metric"
( \Object
x ->
Maybe Text -> Text -> AggregationFunction -> Metric
Metric'
(Maybe Text -> Text -> AggregationFunction -> Metric)
-> Parser (Maybe Text)
-> Parser (Text -> AggregationFunction -> Metric)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Namespace")
Parser (Text -> AggregationFunction -> Metric)
-> Parser Text -> Parser (AggregationFunction -> Metric)
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
"MetricName")
Parser (AggregationFunction -> Metric)
-> Parser AggregationFunction -> Parser Metric
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser AggregationFunction
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"AggregationFunction")
)
instance Prelude.Hashable Metric
instance Prelude.NFData Metric
instance Core.ToJSON Metric where
toJSON :: Metric -> Value
toJSON Metric' {Maybe Text
Text
AggregationFunction
aggregationFunction :: AggregationFunction
metricName :: Text
namespace :: Maybe Text
$sel:aggregationFunction:Metric' :: Metric -> AggregationFunction
$sel:metricName:Metric' :: Metric -> Text
$sel:namespace:Metric' :: Metric -> Maybe Text
..} =
[Pair] -> Value
Core.object
( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
[ (Text
"Namespace" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
namespace,
Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"MetricName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
metricName),
Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
(Text
"AggregationFunction" Text -> AggregationFunction -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= AggregationFunction
aggregationFunction)
]
)