{-# 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.IoTSiteWise.Types.Metric where
import qualified Amazonka.Core as Core
import Amazonka.IoTSiteWise.Types.ExpressionVariable
import Amazonka.IoTSiteWise.Types.MetricProcessingConfig
import Amazonka.IoTSiteWise.Types.MetricWindow
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
data Metric = Metric'
{
Metric -> Maybe MetricProcessingConfig
processingConfig :: Prelude.Maybe MetricProcessingConfig,
Metric -> Text
expression :: Prelude.Text,
Metric -> [ExpressionVariable]
variables :: [ExpressionVariable],
Metric -> MetricWindow
window :: MetricWindow
}
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 ->
MetricWindow ->
Metric
newMetric :: Text -> MetricWindow -> Metric
newMetric Text
pExpression_ MetricWindow
pWindow_ =
Metric' :: Maybe MetricProcessingConfig
-> Text -> [ExpressionVariable] -> MetricWindow -> Metric
Metric'
{ $sel:processingConfig:Metric' :: Maybe MetricProcessingConfig
processingConfig = Maybe MetricProcessingConfig
forall a. Maybe a
Prelude.Nothing,
$sel:expression:Metric' :: Text
expression = Text
pExpression_,
$sel:variables:Metric' :: [ExpressionVariable]
variables = [ExpressionVariable]
forall a. Monoid a => a
Prelude.mempty,
$sel:window:Metric' :: MetricWindow
window = MetricWindow
pWindow_
}
metric_processingConfig :: Lens.Lens' Metric (Prelude.Maybe MetricProcessingConfig)
metric_processingConfig :: (Maybe MetricProcessingConfig -> f (Maybe MetricProcessingConfig))
-> Metric -> f Metric
metric_processingConfig = (Metric -> Maybe MetricProcessingConfig)
-> (Metric -> Maybe MetricProcessingConfig -> Metric)
-> Lens
Metric
Metric
(Maybe MetricProcessingConfig)
(Maybe MetricProcessingConfig)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Metric' {Maybe MetricProcessingConfig
processingConfig :: Maybe MetricProcessingConfig
$sel:processingConfig:Metric' :: Metric -> Maybe MetricProcessingConfig
processingConfig} -> Maybe MetricProcessingConfig
processingConfig) (\s :: Metric
s@Metric' {} Maybe MetricProcessingConfig
a -> Metric
s {$sel:processingConfig:Metric' :: Maybe MetricProcessingConfig
processingConfig = Maybe MetricProcessingConfig
a} :: Metric)
metric_expression :: Lens.Lens' Metric Prelude.Text
metric_expression :: (Text -> f Text) -> Metric -> f Metric
metric_expression = (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
expression :: Text
$sel:expression:Metric' :: Metric -> Text
expression} -> Text
expression) (\s :: Metric
s@Metric' {} Text
a -> Metric
s {$sel:expression:Metric' :: Text
expression = Text
a} :: Metric)
metric_variables :: Lens.Lens' Metric [ExpressionVariable]
metric_variables :: ([ExpressionVariable] -> f [ExpressionVariable])
-> Metric -> f Metric
metric_variables = (Metric -> [ExpressionVariable])
-> (Metric -> [ExpressionVariable] -> Metric)
-> Lens Metric Metric [ExpressionVariable] [ExpressionVariable]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Metric' {[ExpressionVariable]
variables :: [ExpressionVariable]
$sel:variables:Metric' :: Metric -> [ExpressionVariable]
variables} -> [ExpressionVariable]
variables) (\s :: Metric
s@Metric' {} [ExpressionVariable]
a -> Metric
s {$sel:variables:Metric' :: [ExpressionVariable]
variables = [ExpressionVariable]
a} :: Metric) (([ExpressionVariable] -> f [ExpressionVariable])
-> Metric -> f Metric)
-> (([ExpressionVariable] -> f [ExpressionVariable])
-> [ExpressionVariable] -> f [ExpressionVariable])
-> ([ExpressionVariable] -> f [ExpressionVariable])
-> Metric
-> f Metric
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([ExpressionVariable] -> f [ExpressionVariable])
-> [ExpressionVariable] -> f [ExpressionVariable]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced
metric_window :: Lens.Lens' Metric MetricWindow
metric_window :: (MetricWindow -> f MetricWindow) -> Metric -> f Metric
metric_window = (Metric -> MetricWindow)
-> (Metric -> MetricWindow -> Metric)
-> Lens Metric Metric MetricWindow MetricWindow
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Metric' {MetricWindow
window :: MetricWindow
$sel:window:Metric' :: Metric -> MetricWindow
window} -> MetricWindow
window) (\s :: Metric
s@Metric' {} MetricWindow
a -> Metric
s {$sel:window:Metric' :: MetricWindow
window = MetricWindow
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 MetricProcessingConfig
-> Text -> [ExpressionVariable] -> MetricWindow -> Metric
Metric'
(Maybe MetricProcessingConfig
-> Text -> [ExpressionVariable] -> MetricWindow -> Metric)
-> Parser (Maybe MetricProcessingConfig)
-> Parser (Text -> [ExpressionVariable] -> MetricWindow -> Metric)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe MetricProcessingConfig)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"processingConfig")
Parser (Text -> [ExpressionVariable] -> MetricWindow -> Metric)
-> Parser Text
-> Parser ([ExpressionVariable] -> MetricWindow -> 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
"expression")
Parser ([ExpressionVariable] -> MetricWindow -> Metric)
-> Parser [ExpressionVariable] -> Parser (MetricWindow -> Metric)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe [ExpressionVariable])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"variables" Parser (Maybe [ExpressionVariable])
-> [ExpressionVariable] -> Parser [ExpressionVariable]
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= [ExpressionVariable]
forall a. Monoid a => a
Prelude.mempty)
Parser (MetricWindow -> Metric)
-> Parser MetricWindow -> Parser Metric
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser MetricWindow
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"window")
)
instance Prelude.Hashable Metric
instance Prelude.NFData Metric
instance Core.ToJSON Metric where
toJSON :: Metric -> Value
toJSON Metric' {[ExpressionVariable]
Maybe MetricProcessingConfig
Text
MetricWindow
window :: MetricWindow
variables :: [ExpressionVariable]
expression :: Text
processingConfig :: Maybe MetricProcessingConfig
$sel:window:Metric' :: Metric -> MetricWindow
$sel:variables:Metric' :: Metric -> [ExpressionVariable]
$sel:expression:Metric' :: Metric -> Text
$sel:processingConfig:Metric' :: Metric -> Maybe MetricProcessingConfig
..} =
[Pair] -> Value
Core.object
( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
[ (Text
"processingConfig" Text -> MetricProcessingConfig -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
(MetricProcessingConfig -> Pair)
-> Maybe MetricProcessingConfig -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe MetricProcessingConfig
processingConfig,
Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"expression" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
expression),
Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"variables" Text -> [ExpressionVariable] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= [ExpressionVariable]
variables),
Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"window" Text -> MetricWindow -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= MetricWindow
window)
]
)