{-# 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-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.IoTEvents.Types.AssetPropertyTimestamp where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(AssetPropertyTimestamp -> AssetPropertyTimestamp -> Bool)
-> (AssetPropertyTimestamp -> AssetPropertyTimestamp -> Bool)
-> Eq AssetPropertyTimestamp
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]
(Int -> ReadS AssetPropertyTimestamp)
-> ReadS [AssetPropertyTimestamp]
-> ReadPrec AssetPropertyTimestamp
-> ReadPrec [AssetPropertyTimestamp]
-> Read 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
(Int -> AssetPropertyTimestamp -> ShowS)
-> (AssetPropertyTimestamp -> String)
-> ([AssetPropertyTimestamp] -> ShowS)
-> Show AssetPropertyTimestamp
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. AssetPropertyTimestamp -> Rep AssetPropertyTimestamp x)
-> (forall x.
    Rep AssetPropertyTimestamp x -> AssetPropertyTimestamp)
-> Generic AssetPropertyTimestamp
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' :: Maybe Text -> Text -> AssetPropertyTimestamp
AssetPropertyTimestamp'
    { $sel:offsetInNanos:AssetPropertyTimestamp' :: Maybe Text
offsetInNanos =
        Maybe Text
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 :: (Maybe Text -> f (Maybe Text))
-> AssetPropertyTimestamp -> f AssetPropertyTimestamp
assetPropertyTimestamp_offsetInNanos = (AssetPropertyTimestamp -> Maybe Text)
-> (AssetPropertyTimestamp -> Maybe Text -> AssetPropertyTimestamp)
-> Lens
     AssetPropertyTimestamp
     AssetPropertyTimestamp
     (Maybe Text)
     (Maybe Text)
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 :: (Text -> f Text)
-> AssetPropertyTimestamp -> f AssetPropertyTimestamp
assetPropertyTimestamp_timeInSeconds = (AssetPropertyTimestamp -> Text)
-> (AssetPropertyTimestamp -> Text -> AssetPropertyTimestamp)
-> Lens AssetPropertyTimestamp AssetPropertyTimestamp Text Text
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 Core.FromJSON AssetPropertyTimestamp where
  parseJSON :: Value -> Parser AssetPropertyTimestamp
parseJSON =
    String
-> (Object -> Parser AssetPropertyTimestamp)
-> Value
-> Parser AssetPropertyTimestamp
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"AssetPropertyTimestamp"
      ( \Object
x ->
          Maybe Text -> Text -> AssetPropertyTimestamp
AssetPropertyTimestamp'
            (Maybe Text -> Text -> AssetPropertyTimestamp)
-> Parser (Maybe Text) -> Parser (Text -> AssetPropertyTimestamp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"offsetInNanos")
            Parser (Text -> AssetPropertyTimestamp)
-> Parser Text -> Parser AssetPropertyTimestamp
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"timeInSeconds")
      )

instance Prelude.Hashable AssetPropertyTimestamp

instance Prelude.NFData AssetPropertyTimestamp

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"offsetInNanos" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
offsetInNanos,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"timeInSeconds" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
timeInSeconds)
          ]
      )