{-# 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.IoTEvents.Types.AssetPropertyTimestamp
-- 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.IoTEvents.Types.AssetPropertyTimestamp 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 structure that contains timestamp information. For more information,
-- see
-- <https://docs.aws.amazon.com/iot-sitewise/latest/APIReference/API_TimeInNanos.html TimeInNanos>
-- in the /AWS IoT SiteWise API Reference/.
--
-- You must use expressions for all parameters in @AssetPropertyTimestamp@.
-- The expressions accept literals, operators, functions, references, and
-- substitution templates.
--
-- __Examples__
--
-- -   For literal values, the expressions must contain single quotes. For
--     example, the value for the @timeInSeconds@ parameter can be
--     @\'1586400675\'@.
--
-- -   For references, you must specify either variables or input values.
--     For example, the value for the @offsetInNanos@ parameter can be
--     @$variable.time@.
--
-- -   For a substitution template, you must use @${}@, and the template
--     must be in single quotes. A substitution template can also contain a
--     combination of literals, operators, functions, references, and
--     substitution templates.
--
--     In the following example, the value for the @timeInSeconds@
--     parameter uses a substitution template.
--
--     @\'${$input.TemperatureInput.sensorData.timestamp \/ 1000}\'@
--
-- For more information, see
-- <https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-expressions.html Expressions>
-- in the /AWS IoT Events Developer Guide/.
--
-- /See:/ 'newAssetPropertyTimestamp' smart constructor.
data AssetPropertyTimestamp = AssetPropertyTimestamp'
  { -- | The nanosecond offset converted from @timeInSeconds@. The valid range is
    -- between 0-999999999.
    AssetPropertyTimestamp -> Maybe Text
offsetInNanos :: Prelude.Maybe Prelude.Text,
    -- | The timestamp, in seconds, in the Unix epoch format. The valid range is
    -- between 1-31556889864403199.
    AssetPropertyTimestamp -> Text
timeInSeconds :: Prelude.Text
  }
  deriving (AssetPropertyTimestamp -> AssetPropertyTimestamp -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AssetPropertyTimestamp -> AssetPropertyTimestamp -> Bool
$c/= :: AssetPropertyTimestamp -> AssetPropertyTimestamp -> Bool
== :: AssetPropertyTimestamp -> AssetPropertyTimestamp -> Bool
$c== :: AssetPropertyTimestamp -> AssetPropertyTimestamp -> Bool
Prelude.Eq, ReadPrec [AssetPropertyTimestamp]
ReadPrec AssetPropertyTimestamp
Int -> ReadS AssetPropertyTimestamp
ReadS [AssetPropertyTimestamp]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AssetPropertyTimestamp]
$creadListPrec :: ReadPrec [AssetPropertyTimestamp]
readPrec :: ReadPrec AssetPropertyTimestamp
$creadPrec :: ReadPrec AssetPropertyTimestamp
readList :: ReadS [AssetPropertyTimestamp]
$creadList :: ReadS [AssetPropertyTimestamp]
readsPrec :: Int -> ReadS AssetPropertyTimestamp
$creadsPrec :: Int -> ReadS AssetPropertyTimestamp
Prelude.Read, Int -> AssetPropertyTimestamp -> ShowS
[AssetPropertyTimestamp] -> ShowS
AssetPropertyTimestamp -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AssetPropertyTimestamp] -> ShowS
$cshowList :: [AssetPropertyTimestamp] -> ShowS
show :: AssetPropertyTimestamp -> String
$cshow :: AssetPropertyTimestamp -> String
showsPrec :: Int -> AssetPropertyTimestamp -> ShowS
$cshowsPrec :: Int -> AssetPropertyTimestamp -> ShowS
Prelude.Show, forall x. Rep AssetPropertyTimestamp x -> AssetPropertyTimestamp
forall x. AssetPropertyTimestamp -> Rep AssetPropertyTimestamp x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep AssetPropertyTimestamp x -> AssetPropertyTimestamp
$cfrom :: forall x. AssetPropertyTimestamp -> Rep AssetPropertyTimestamp x
Prelude.Generic)

-- |
-- Create a value of 'AssetPropertyTimestamp' 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:
--
-- 'offsetInNanos', 'assetPropertyTimestamp_offsetInNanos' - The nanosecond offset converted from @timeInSeconds@. The valid range is
-- between 0-999999999.
--
-- 'timeInSeconds', 'assetPropertyTimestamp_timeInSeconds' - The timestamp, in seconds, in the Unix epoch format. The valid range is
-- between 1-31556889864403199.
newAssetPropertyTimestamp ::
  -- | 'timeInSeconds'
  Prelude.Text ->
  AssetPropertyTimestamp
newAssetPropertyTimestamp :: Text -> AssetPropertyTimestamp
newAssetPropertyTimestamp Text
pTimeInSeconds_ =
  AssetPropertyTimestamp'
    { $sel:offsetInNanos:AssetPropertyTimestamp' :: Maybe Text
offsetInNanos =
        forall a. Maybe a
Prelude.Nothing,
      $sel:timeInSeconds:AssetPropertyTimestamp' :: Text
timeInSeconds = Text
pTimeInSeconds_
    }

-- | The nanosecond offset converted from @timeInSeconds@. The valid range is
-- between 0-999999999.
assetPropertyTimestamp_offsetInNanos :: Lens.Lens' AssetPropertyTimestamp (Prelude.Maybe Prelude.Text)
assetPropertyTimestamp_offsetInNanos :: Lens' AssetPropertyTimestamp (Maybe Text)
assetPropertyTimestamp_offsetInNanos = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssetPropertyTimestamp' {Maybe Text
offsetInNanos :: Maybe Text
$sel:offsetInNanos:AssetPropertyTimestamp' :: AssetPropertyTimestamp -> Maybe Text
offsetInNanos} -> Maybe Text
offsetInNanos) (\s :: AssetPropertyTimestamp
s@AssetPropertyTimestamp' {} Maybe Text
a -> AssetPropertyTimestamp
s {$sel:offsetInNanos:AssetPropertyTimestamp' :: Maybe Text
offsetInNanos = Maybe Text
a} :: AssetPropertyTimestamp)

-- | The timestamp, in seconds, in the Unix epoch format. The valid range is
-- between 1-31556889864403199.
assetPropertyTimestamp_timeInSeconds :: Lens.Lens' AssetPropertyTimestamp Prelude.Text
assetPropertyTimestamp_timeInSeconds :: Lens' AssetPropertyTimestamp Text
assetPropertyTimestamp_timeInSeconds = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\AssetPropertyTimestamp' {Text
timeInSeconds :: Text
$sel:timeInSeconds:AssetPropertyTimestamp' :: AssetPropertyTimestamp -> Text
timeInSeconds} -> Text
timeInSeconds) (\s :: AssetPropertyTimestamp
s@AssetPropertyTimestamp' {} Text
a -> AssetPropertyTimestamp
s {$sel:timeInSeconds:AssetPropertyTimestamp' :: Text
timeInSeconds = Text
a} :: AssetPropertyTimestamp)

instance Data.FromJSON AssetPropertyTimestamp where
  parseJSON :: Value -> Parser AssetPropertyTimestamp
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"AssetPropertyTimestamp"
      ( \Object
x ->
          Maybe Text -> Text -> AssetPropertyTimestamp
AssetPropertyTimestamp'
            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
"offsetInNanos")
            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
"timeInSeconds")
      )

instance Prelude.Hashable AssetPropertyTimestamp where
  hashWithSalt :: Int -> AssetPropertyTimestamp -> Int
hashWithSalt Int
_salt AssetPropertyTimestamp' {Maybe Text
Text
timeInSeconds :: Text
offsetInNanos :: Maybe Text
$sel:timeInSeconds:AssetPropertyTimestamp' :: AssetPropertyTimestamp -> Text
$sel:offsetInNanos:AssetPropertyTimestamp' :: AssetPropertyTimestamp -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
offsetInNanos
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
timeInSeconds

instance Prelude.NFData AssetPropertyTimestamp where
  rnf :: AssetPropertyTimestamp -> ()
rnf AssetPropertyTimestamp' {Maybe Text
Text
timeInSeconds :: Text
offsetInNanos :: Maybe Text
$sel:timeInSeconds:AssetPropertyTimestamp' :: AssetPropertyTimestamp -> Text
$sel:offsetInNanos:AssetPropertyTimestamp' :: AssetPropertyTimestamp -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
offsetInNanos
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
timeInSeconds

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