{-# 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.Pi.Types.DataPoint
-- 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.Pi.Types.DataPoint where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A timestamp, and a single numerical value, which together represent a
-- measurement at a particular point in time.
--
-- /See:/ 'newDataPoint' smart constructor.
data DataPoint = DataPoint'
  { -- | The time, in epoch format, associated with a particular @Value@.
    DataPoint -> POSIX
timestamp :: Core.POSIX,
    -- | The actual value associated with a particular @Timestamp@.
    DataPoint -> Double
value :: Prelude.Double
  }
  deriving (DataPoint -> DataPoint -> Bool
(DataPoint -> DataPoint -> Bool)
-> (DataPoint -> DataPoint -> Bool) -> Eq DataPoint
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DataPoint -> DataPoint -> Bool
$c/= :: DataPoint -> DataPoint -> Bool
== :: DataPoint -> DataPoint -> Bool
$c== :: DataPoint -> DataPoint -> Bool
Prelude.Eq, ReadPrec [DataPoint]
ReadPrec DataPoint
Int -> ReadS DataPoint
ReadS [DataPoint]
(Int -> ReadS DataPoint)
-> ReadS [DataPoint]
-> ReadPrec DataPoint
-> ReadPrec [DataPoint]
-> Read DataPoint
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DataPoint]
$creadListPrec :: ReadPrec [DataPoint]
readPrec :: ReadPrec DataPoint
$creadPrec :: ReadPrec DataPoint
readList :: ReadS [DataPoint]
$creadList :: ReadS [DataPoint]
readsPrec :: Int -> ReadS DataPoint
$creadsPrec :: Int -> ReadS DataPoint
Prelude.Read, Int -> DataPoint -> ShowS
[DataPoint] -> ShowS
DataPoint -> String
(Int -> DataPoint -> ShowS)
-> (DataPoint -> String)
-> ([DataPoint] -> ShowS)
-> Show DataPoint
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DataPoint] -> ShowS
$cshowList :: [DataPoint] -> ShowS
show :: DataPoint -> String
$cshow :: DataPoint -> String
showsPrec :: Int -> DataPoint -> ShowS
$cshowsPrec :: Int -> DataPoint -> ShowS
Prelude.Show, (forall x. DataPoint -> Rep DataPoint x)
-> (forall x. Rep DataPoint x -> DataPoint) -> Generic DataPoint
forall x. Rep DataPoint x -> DataPoint
forall x. DataPoint -> Rep DataPoint x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DataPoint x -> DataPoint
$cfrom :: forall x. DataPoint -> Rep DataPoint x
Prelude.Generic)

-- |
-- Create a value of 'DataPoint' 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', 'dataPoint_timestamp' - The time, in epoch format, associated with a particular @Value@.
--
-- 'value', 'dataPoint_value' - The actual value associated with a particular @Timestamp@.
newDataPoint ::
  -- | 'timestamp'
  Prelude.UTCTime ->
  -- | 'value'
  Prelude.Double ->
  DataPoint
newDataPoint :: UTCTime -> Double -> DataPoint
newDataPoint UTCTime
pTimestamp_ Double
pValue_ =
  DataPoint' :: POSIX -> Double -> DataPoint
DataPoint'
    { $sel:timestamp:DataPoint' :: POSIX
timestamp =
        Tagged UTCTime (Identity UTCTime) -> Tagged POSIX (Identity POSIX)
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time (Tagged UTCTime (Identity UTCTime)
 -> Tagged POSIX (Identity POSIX))
-> UTCTime -> POSIX
forall t b. AReview t b -> b -> t
Lens.# UTCTime
pTimestamp_,
      $sel:value:DataPoint' :: Double
value = Double
pValue_
    }

-- | The time, in epoch format, associated with a particular @Value@.
dataPoint_timestamp :: Lens.Lens' DataPoint Prelude.UTCTime
dataPoint_timestamp :: (UTCTime -> f UTCTime) -> DataPoint -> f DataPoint
dataPoint_timestamp = (DataPoint -> POSIX)
-> (DataPoint -> POSIX -> DataPoint)
-> Lens DataPoint DataPoint POSIX POSIX
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DataPoint' {POSIX
timestamp :: POSIX
$sel:timestamp:DataPoint' :: DataPoint -> POSIX
timestamp} -> POSIX
timestamp) (\s :: DataPoint
s@DataPoint' {} POSIX
a -> DataPoint
s {$sel:timestamp:DataPoint' :: POSIX
timestamp = POSIX
a} :: DataPoint) ((POSIX -> f POSIX) -> DataPoint -> f DataPoint)
-> ((UTCTime -> f UTCTime) -> POSIX -> f POSIX)
-> (UTCTime -> f UTCTime)
-> DataPoint
-> f DataPoint
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (UTCTime -> f UTCTime) -> POSIX -> f POSIX
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | The actual value associated with a particular @Timestamp@.
dataPoint_value :: Lens.Lens' DataPoint Prelude.Double
dataPoint_value :: (Double -> f Double) -> DataPoint -> f DataPoint
dataPoint_value = (DataPoint -> Double)
-> (DataPoint -> Double -> DataPoint)
-> Lens DataPoint DataPoint Double Double
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DataPoint' {Double
value :: Double
$sel:value:DataPoint' :: DataPoint -> Double
value} -> Double
value) (\s :: DataPoint
s@DataPoint' {} Double
a -> DataPoint
s {$sel:value:DataPoint' :: Double
value = Double
a} :: DataPoint)

instance Core.FromJSON DataPoint where
  parseJSON :: Value -> Parser DataPoint
parseJSON =
    String -> (Object -> Parser DataPoint) -> Value -> Parser DataPoint
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"DataPoint"
      ( \Object
x ->
          POSIX -> Double -> DataPoint
DataPoint'
            (POSIX -> Double -> DataPoint)
-> Parser POSIX -> Parser (Double -> DataPoint)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser POSIX
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Timestamp")
            Parser (Double -> DataPoint) -> Parser Double -> Parser DataPoint
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Double
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Value")
      )

instance Prelude.Hashable DataPoint

instance Prelude.NFData DataPoint