{-# 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.IotTwinMaker.Types.PropertyValue
-- 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.IotTwinMaker.Types.PropertyValue where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IotTwinMaker.Types.DataValue
import qualified Amazonka.Prelude as Prelude

-- | An object that contains information about a value for a time series
-- property.
--
-- /See:/ 'newPropertyValue' smart constructor.
data PropertyValue = PropertyValue'
  { -- | ISO8601 DateTime of a value for a time series property.
    --
    -- The time for when the property value was recorded in ISO 8601 format:
    -- /YYYY-MM-DDThh:mm:ss[.SSSSSSSSS][Z\/±HH:mm]/.
    --
    -- -   /[YYYY]/: year
    --
    -- -   /[MM]/: month
    --
    -- -   /[DD]/: day
    --
    -- -   /[hh]/: hour
    --
    -- -   /[mm]/: minute
    --
    -- -   /[ss]/: seconds
    --
    -- -   /[.SSSSSSSSS]/: additional precision, where precedence is
    --     maintained. For example: [.573123] is equal to 573123000
    --     nanoseconds.
    --
    -- -   /Z/: default timezone UTC
    --
    -- -   /± HH:mm/: time zone offset in Hours and Minutes.
    --
    -- /Required sub-fields/: YYYY-MM-DDThh:mm:ss and [Z\/±HH:mm]
    PropertyValue -> Maybe Text
time :: Prelude.Maybe Prelude.Text,
    -- | The timestamp of a value for a time series property.
    PropertyValue -> Maybe POSIX
timestamp :: Prelude.Maybe Data.POSIX,
    -- | An object that specifies a value for a time series property.
    PropertyValue -> DataValue
value :: DataValue
  }
  deriving (PropertyValue -> PropertyValue -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PropertyValue -> PropertyValue -> Bool
$c/= :: PropertyValue -> PropertyValue -> Bool
== :: PropertyValue -> PropertyValue -> Bool
$c== :: PropertyValue -> PropertyValue -> Bool
Prelude.Eq, ReadPrec [PropertyValue]
ReadPrec PropertyValue
Int -> ReadS PropertyValue
ReadS [PropertyValue]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PropertyValue]
$creadListPrec :: ReadPrec [PropertyValue]
readPrec :: ReadPrec PropertyValue
$creadPrec :: ReadPrec PropertyValue
readList :: ReadS [PropertyValue]
$creadList :: ReadS [PropertyValue]
readsPrec :: Int -> ReadS PropertyValue
$creadsPrec :: Int -> ReadS PropertyValue
Prelude.Read, Int -> PropertyValue -> ShowS
[PropertyValue] -> ShowS
PropertyValue -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PropertyValue] -> ShowS
$cshowList :: [PropertyValue] -> ShowS
show :: PropertyValue -> String
$cshow :: PropertyValue -> String
showsPrec :: Int -> PropertyValue -> ShowS
$cshowsPrec :: Int -> PropertyValue -> ShowS
Prelude.Show, forall x. Rep PropertyValue x -> PropertyValue
forall x. PropertyValue -> Rep PropertyValue x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PropertyValue x -> PropertyValue
$cfrom :: forall x. PropertyValue -> Rep PropertyValue x
Prelude.Generic)

-- |
-- Create a value of 'PropertyValue' 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:
--
-- 'time', 'propertyValue_time' - ISO8601 DateTime of a value for a time series property.
--
-- The time for when the property value was recorded in ISO 8601 format:
-- /YYYY-MM-DDThh:mm:ss[.SSSSSSSSS][Z\/±HH:mm]/.
--
-- -   /[YYYY]/: year
--
-- -   /[MM]/: month
--
-- -   /[DD]/: day
--
-- -   /[hh]/: hour
--
-- -   /[mm]/: minute
--
-- -   /[ss]/: seconds
--
-- -   /[.SSSSSSSSS]/: additional precision, where precedence is
--     maintained. For example: [.573123] is equal to 573123000
--     nanoseconds.
--
-- -   /Z/: default timezone UTC
--
-- -   /± HH:mm/: time zone offset in Hours and Minutes.
--
-- /Required sub-fields/: YYYY-MM-DDThh:mm:ss and [Z\/±HH:mm]
--
-- 'timestamp', 'propertyValue_timestamp' - The timestamp of a value for a time series property.
--
-- 'value', 'propertyValue_value' - An object that specifies a value for a time series property.
newPropertyValue ::
  -- | 'value'
  DataValue ->
  PropertyValue
newPropertyValue :: DataValue -> PropertyValue
newPropertyValue DataValue
pValue_ =
  PropertyValue'
    { $sel:time:PropertyValue' :: Maybe Text
time = forall a. Maybe a
Prelude.Nothing,
      $sel:timestamp:PropertyValue' :: Maybe POSIX
timestamp = forall a. Maybe a
Prelude.Nothing,
      $sel:value:PropertyValue' :: DataValue
value = DataValue
pValue_
    }

-- | ISO8601 DateTime of a value for a time series property.
--
-- The time for when the property value was recorded in ISO 8601 format:
-- /YYYY-MM-DDThh:mm:ss[.SSSSSSSSS][Z\/±HH:mm]/.
--
-- -   /[YYYY]/: year
--
-- -   /[MM]/: month
--
-- -   /[DD]/: day
--
-- -   /[hh]/: hour
--
-- -   /[mm]/: minute
--
-- -   /[ss]/: seconds
--
-- -   /[.SSSSSSSSS]/: additional precision, where precedence is
--     maintained. For example: [.573123] is equal to 573123000
--     nanoseconds.
--
-- -   /Z/: default timezone UTC
--
-- -   /± HH:mm/: time zone offset in Hours and Minutes.
--
-- /Required sub-fields/: YYYY-MM-DDThh:mm:ss and [Z\/±HH:mm]
propertyValue_time :: Lens.Lens' PropertyValue (Prelude.Maybe Prelude.Text)
propertyValue_time :: Lens' PropertyValue (Maybe Text)
propertyValue_time = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PropertyValue' {Maybe Text
time :: Maybe Text
$sel:time:PropertyValue' :: PropertyValue -> Maybe Text
time} -> Maybe Text
time) (\s :: PropertyValue
s@PropertyValue' {} Maybe Text
a -> PropertyValue
s {$sel:time:PropertyValue' :: Maybe Text
time = Maybe Text
a} :: PropertyValue)

-- | The timestamp of a value for a time series property.
propertyValue_timestamp :: Lens.Lens' PropertyValue (Prelude.Maybe Prelude.UTCTime)
propertyValue_timestamp :: Lens' PropertyValue (Maybe UTCTime)
propertyValue_timestamp = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PropertyValue' {Maybe POSIX
timestamp :: Maybe POSIX
$sel:timestamp:PropertyValue' :: PropertyValue -> Maybe POSIX
timestamp} -> Maybe POSIX
timestamp) (\s :: PropertyValue
s@PropertyValue' {} Maybe POSIX
a -> PropertyValue
s {$sel:timestamp:PropertyValue' :: Maybe POSIX
timestamp = Maybe POSIX
a} :: PropertyValue) 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

-- | An object that specifies a value for a time series property.
propertyValue_value :: Lens.Lens' PropertyValue DataValue
propertyValue_value :: Lens' PropertyValue DataValue
propertyValue_value = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PropertyValue' {DataValue
value :: DataValue
$sel:value:PropertyValue' :: PropertyValue -> DataValue
value} -> DataValue
value) (\s :: PropertyValue
s@PropertyValue' {} DataValue
a -> PropertyValue
s {$sel:value:PropertyValue' :: DataValue
value = DataValue
a} :: PropertyValue)

instance Data.FromJSON PropertyValue where
  parseJSON :: Value -> Parser PropertyValue
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"PropertyValue"
      ( \Object
x ->
          Maybe Text -> Maybe POSIX -> DataValue -> PropertyValue
PropertyValue'
            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
"time")
            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
"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 PropertyValue where
  hashWithSalt :: Int -> PropertyValue -> Int
hashWithSalt Int
_salt PropertyValue' {Maybe Text
Maybe POSIX
DataValue
value :: DataValue
timestamp :: Maybe POSIX
time :: Maybe Text
$sel:value:PropertyValue' :: PropertyValue -> DataValue
$sel:timestamp:PropertyValue' :: PropertyValue -> Maybe POSIX
$sel:time:PropertyValue' :: PropertyValue -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
time
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
timestamp
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` DataValue
value

instance Prelude.NFData PropertyValue where
  rnf :: PropertyValue -> ()
rnf PropertyValue' {Maybe Text
Maybe POSIX
DataValue
value :: DataValue
timestamp :: Maybe POSIX
time :: Maybe Text
$sel:value:PropertyValue' :: PropertyValue -> DataValue
$sel:timestamp:PropertyValue' :: PropertyValue -> Maybe POSIX
$sel:time:PropertyValue' :: PropertyValue -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
time
      seq :: forall a b. a -> b -> b
`Prelude.seq` 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 DataValue
value

instance Data.ToJSON PropertyValue where
  toJSON :: PropertyValue -> Value
toJSON PropertyValue' {Maybe Text
Maybe POSIX
DataValue
value :: DataValue
timestamp :: Maybe POSIX
time :: Maybe Text
$sel:value:PropertyValue' :: PropertyValue -> DataValue
$sel:timestamp:PropertyValue' :: PropertyValue -> Maybe POSIX
$sel:time:PropertyValue' :: PropertyValue -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"time" 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 Text
time,
            (Key
"timestamp" 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 POSIX
timestamp,
            forall a. a -> Maybe a
Prelude.Just (Key
"value" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= DataValue
value)
          ]
      )