{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Pi.Types.DataPoint where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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 :: Data.POSIX,
    -- | The actual value associated with a particular @Timestamp@.
    DataPoint -> Double
value :: Prelude.Double
  }
  deriving (DataPoint -> DataPoint -> Bool
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]
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
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. 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'
    { $sel:timestamp:DataPoint' :: POSIX
timestamp =
        forall (a :: Format). Iso' (Time a) UTCTime
Data._Time 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 :: Lens' DataPoint UTCTime
dataPoint_timestamp = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | The actual value associated with a particular @Timestamp@.
dataPoint_value :: Lens.Lens' DataPoint Prelude.Double
dataPoint_value :: Lens' DataPoint Double
dataPoint_value = 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 Data.FromJSON DataPoint where
  parseJSON :: Value -> Parser DataPoint
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"DataPoint"
      ( \Object
x ->
          POSIX -> Double -> DataPoint
DataPoint'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser 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 a
Data..: Key
"Value")
      )

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

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