{-# 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.MetricDatum
-- 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.MetricDatum 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.MetricValue
import qualified Amazonka.Prelude as Prelude

-- | A metric.
--
-- /See:/ 'newMetricDatum' smart constructor.
data MetricDatum = MetricDatum'
  { -- | The time the metric value was reported.
    MetricDatum -> Maybe POSIX
timestamp :: Prelude.Maybe Data.POSIX,
    -- | The value reported for the metric.
    MetricDatum -> Maybe MetricValue
value :: Prelude.Maybe MetricValue
  }
  deriving (MetricDatum -> MetricDatum -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MetricDatum -> MetricDatum -> Bool
$c/= :: MetricDatum -> MetricDatum -> Bool
== :: MetricDatum -> MetricDatum -> Bool
$c== :: MetricDatum -> MetricDatum -> Bool
Prelude.Eq, ReadPrec [MetricDatum]
ReadPrec MetricDatum
Int -> ReadS MetricDatum
ReadS [MetricDatum]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MetricDatum]
$creadListPrec :: ReadPrec [MetricDatum]
readPrec :: ReadPrec MetricDatum
$creadPrec :: ReadPrec MetricDatum
readList :: ReadS [MetricDatum]
$creadList :: ReadS [MetricDatum]
readsPrec :: Int -> ReadS MetricDatum
$creadsPrec :: Int -> ReadS MetricDatum
Prelude.Read, Int -> MetricDatum -> ShowS
[MetricDatum] -> ShowS
MetricDatum -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MetricDatum] -> ShowS
$cshowList :: [MetricDatum] -> ShowS
show :: MetricDatum -> String
$cshow :: MetricDatum -> String
showsPrec :: Int -> MetricDatum -> ShowS
$cshowsPrec :: Int -> MetricDatum -> ShowS
Prelude.Show, forall x. Rep MetricDatum x -> MetricDatum
forall x. MetricDatum -> Rep MetricDatum x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MetricDatum x -> MetricDatum
$cfrom :: forall x. MetricDatum -> Rep MetricDatum x
Prelude.Generic)

-- |
-- Create a value of 'MetricDatum' 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:
--
-- 'timestamp', 'metricDatum_timestamp' - The time the metric value was reported.
--
-- 'value', 'metricDatum_value' - The value reported for the metric.
newMetricDatum ::
  MetricDatum
newMetricDatum :: MetricDatum
newMetricDatum =
  MetricDatum'
    { $sel:timestamp:MetricDatum' :: Maybe POSIX
timestamp = forall a. Maybe a
Prelude.Nothing,
      $sel:value:MetricDatum' :: Maybe MetricValue
value = forall a. Maybe a
Prelude.Nothing
    }

-- | The time the metric value was reported.
metricDatum_timestamp :: Lens.Lens' MetricDatum (Prelude.Maybe Prelude.UTCTime)
metricDatum_timestamp :: Lens' MetricDatum (Maybe UTCTime)
metricDatum_timestamp = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricDatum' {Maybe POSIX
timestamp :: Maybe POSIX
$sel:timestamp:MetricDatum' :: MetricDatum -> Maybe POSIX
timestamp} -> Maybe POSIX
timestamp) (\s :: MetricDatum
s@MetricDatum' {} Maybe POSIX
a -> MetricDatum
s {$sel:timestamp:MetricDatum' :: Maybe POSIX
timestamp = Maybe POSIX
a} :: MetricDatum) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | The value reported for the metric.
metricDatum_value :: Lens.Lens' MetricDatum (Prelude.Maybe MetricValue)
metricDatum_value :: Lens' MetricDatum (Maybe MetricValue)
metricDatum_value = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricDatum' {Maybe MetricValue
value :: Maybe MetricValue
$sel:value:MetricDatum' :: MetricDatum -> Maybe MetricValue
value} -> Maybe MetricValue
value) (\s :: MetricDatum
s@MetricDatum' {} Maybe MetricValue
a -> MetricDatum
s {$sel:value:MetricDatum' :: Maybe MetricValue
value = Maybe MetricValue
a} :: MetricDatum)

instance Data.FromJSON MetricDatum where
  parseJSON :: Value -> Parser MetricDatum
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"MetricDatum"
      ( \Object
x ->
          Maybe POSIX -> Maybe MetricValue -> MetricDatum
MetricDatum'
            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
"timestamp")
            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
"value")
      )

instance Prelude.Hashable MetricDatum where
  hashWithSalt :: Int -> MetricDatum -> Int
hashWithSalt Int
_salt MetricDatum' {Maybe POSIX
Maybe MetricValue
value :: Maybe MetricValue
timestamp :: Maybe POSIX
$sel:value:MetricDatum' :: MetricDatum -> Maybe MetricValue
$sel:timestamp:MetricDatum' :: MetricDatum -> Maybe POSIX
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
timestamp
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe MetricValue
value

instance Prelude.NFData MetricDatum where
  rnf :: MetricDatum -> ()
rnf MetricDatum' {Maybe POSIX
Maybe MetricValue
value :: Maybe MetricValue
timestamp :: Maybe POSIX
$sel:value:MetricDatum' :: MetricDatum -> Maybe MetricValue
$sel:timestamp:MetricDatum' :: MetricDatum -> Maybe POSIX
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
timestamp
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe MetricValue
value