{-# 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 qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IoTSiteWise.Types.ExpressionVariable
import Amazonka.IoTSiteWise.Types.MetricProcessingConfig
import Amazonka.IoTSiteWise.Types.MetricWindow
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
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]
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
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. 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'
{ $sel:processingConfig:Metric' :: Maybe MetricProcessingConfig
processingConfig = forall a. Maybe a
Prelude.Nothing,
$sel:expression:Metric' :: Text
expression = Text
pExpression_,
$sel:variables:Metric' :: [ExpressionVariable]
variables = forall a. Monoid a => a
Prelude.mempty,
$sel:window:Metric' :: MetricWindow
window = MetricWindow
pWindow_
}
metric_processingConfig :: Lens.Lens' Metric (Prelude.Maybe MetricProcessingConfig)
metric_processingConfig :: Lens' Metric (Maybe MetricProcessingConfig)
metric_processingConfig = 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 :: Lens' Metric Text
metric_expression = 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 :: Lens' Metric [ExpressionVariable]
metric_variables = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 :: Lens' Metric MetricWindow
metric_window = 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 Data.FromJSON Metric where
parseJSON :: Value -> Parser Metric
parseJSON =
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
String
"Metric"
( \Object
x ->
Maybe MetricProcessingConfig
-> Text -> [ExpressionVariable] -> MetricWindow -> Metric
Metric'
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
"processingConfig")
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
"expression")
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"variables" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
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
"window")
)
instance Prelude.Hashable Metric where
hashWithSalt :: Int -> Metric -> Int
hashWithSalt Int
_salt 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
..} =
Int
_salt
forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe MetricProcessingConfig
processingConfig
forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
expression
forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` [ExpressionVariable]
variables
forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` MetricWindow
window
instance Prelude.NFData Metric where
rnf :: Metric -> ()
rnf 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
..} =
forall a. NFData a => a -> ()
Prelude.rnf Maybe MetricProcessingConfig
processingConfig
seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
expression
seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [ExpressionVariable]
variables
seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf MetricWindow
window
instance Data.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
Data.object
( forall a. [Maybe a] -> [a]
Prelude.catMaybes
[ (Key
"processingConfig" 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 MetricProcessingConfig
processingConfig,
forall a. a -> Maybe a
Prelude.Just (Key
"expression" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
expression),
forall a. a -> Maybe a
Prelude.Just (Key
"variables" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= [ExpressionVariable]
variables),
forall a. a -> Maybe a
Prelude.Just (Key
"window" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= MetricWindow
window)
]
)