{-# 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.IoT.Types.TimestreamTimestamp
-- 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.IoT.Types.TimestreamTimestamp 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

-- | Describes how to interpret an application-defined timestamp value from
-- an MQTT message payload and the precision of that value.
--
-- /See:/ 'newTimestreamTimestamp' smart constructor.
data TimestreamTimestamp = TimestreamTimestamp'
  { -- | An expression that returns a long epoch time value.
    TimestreamTimestamp -> Text
value :: Prelude.Text,
    -- | The precision of the timestamp value that results from the expression
    -- described in @value@.
    --
    -- Valid values: @SECONDS@ | @MILLISECONDS@ | @MICROSECONDS@ |
    -- @NANOSECONDS@. The default is @MILLISECONDS@.
    TimestreamTimestamp -> Text
unit :: Prelude.Text
  }
  deriving (TimestreamTimestamp -> TimestreamTimestamp -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TimestreamTimestamp -> TimestreamTimestamp -> Bool
$c/= :: TimestreamTimestamp -> TimestreamTimestamp -> Bool
== :: TimestreamTimestamp -> TimestreamTimestamp -> Bool
$c== :: TimestreamTimestamp -> TimestreamTimestamp -> Bool
Prelude.Eq, ReadPrec [TimestreamTimestamp]
ReadPrec TimestreamTimestamp
Int -> ReadS TimestreamTimestamp
ReadS [TimestreamTimestamp]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TimestreamTimestamp]
$creadListPrec :: ReadPrec [TimestreamTimestamp]
readPrec :: ReadPrec TimestreamTimestamp
$creadPrec :: ReadPrec TimestreamTimestamp
readList :: ReadS [TimestreamTimestamp]
$creadList :: ReadS [TimestreamTimestamp]
readsPrec :: Int -> ReadS TimestreamTimestamp
$creadsPrec :: Int -> ReadS TimestreamTimestamp
Prelude.Read, Int -> TimestreamTimestamp -> ShowS
[TimestreamTimestamp] -> ShowS
TimestreamTimestamp -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TimestreamTimestamp] -> ShowS
$cshowList :: [TimestreamTimestamp] -> ShowS
show :: TimestreamTimestamp -> String
$cshow :: TimestreamTimestamp -> String
showsPrec :: Int -> TimestreamTimestamp -> ShowS
$cshowsPrec :: Int -> TimestreamTimestamp -> ShowS
Prelude.Show, forall x. Rep TimestreamTimestamp x -> TimestreamTimestamp
forall x. TimestreamTimestamp -> Rep TimestreamTimestamp x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TimestreamTimestamp x -> TimestreamTimestamp
$cfrom :: forall x. TimestreamTimestamp -> Rep TimestreamTimestamp x
Prelude.Generic)

-- |
-- Create a value of 'TimestreamTimestamp' 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:
--
-- 'value', 'timestreamTimestamp_value' - An expression that returns a long epoch time value.
--
-- 'unit', 'timestreamTimestamp_unit' - The precision of the timestamp value that results from the expression
-- described in @value@.
--
-- Valid values: @SECONDS@ | @MILLISECONDS@ | @MICROSECONDS@ |
-- @NANOSECONDS@. The default is @MILLISECONDS@.
newTimestreamTimestamp ::
  -- | 'value'
  Prelude.Text ->
  -- | 'unit'
  Prelude.Text ->
  TimestreamTimestamp
newTimestreamTimestamp :: Text -> Text -> TimestreamTimestamp
newTimestreamTimestamp Text
pValue_ Text
pUnit_ =
  TimestreamTimestamp'
    { $sel:value:TimestreamTimestamp' :: Text
value = Text
pValue_,
      $sel:unit:TimestreamTimestamp' :: Text
unit = Text
pUnit_
    }

-- | An expression that returns a long epoch time value.
timestreamTimestamp_value :: Lens.Lens' TimestreamTimestamp Prelude.Text
timestreamTimestamp_value :: Lens' TimestreamTimestamp Text
timestreamTimestamp_value = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TimestreamTimestamp' {Text
value :: Text
$sel:value:TimestreamTimestamp' :: TimestreamTimestamp -> Text
value} -> Text
value) (\s :: TimestreamTimestamp
s@TimestreamTimestamp' {} Text
a -> TimestreamTimestamp
s {$sel:value:TimestreamTimestamp' :: Text
value = Text
a} :: TimestreamTimestamp)

-- | The precision of the timestamp value that results from the expression
-- described in @value@.
--
-- Valid values: @SECONDS@ | @MILLISECONDS@ | @MICROSECONDS@ |
-- @NANOSECONDS@. The default is @MILLISECONDS@.
timestreamTimestamp_unit :: Lens.Lens' TimestreamTimestamp Prelude.Text
timestreamTimestamp_unit :: Lens' TimestreamTimestamp Text
timestreamTimestamp_unit = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TimestreamTimestamp' {Text
unit :: Text
$sel:unit:TimestreamTimestamp' :: TimestreamTimestamp -> Text
unit} -> Text
unit) (\s :: TimestreamTimestamp
s@TimestreamTimestamp' {} Text
a -> TimestreamTimestamp
s {$sel:unit:TimestreamTimestamp' :: Text
unit = Text
a} :: TimestreamTimestamp)

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

instance Prelude.Hashable TimestreamTimestamp where
  hashWithSalt :: Int -> TimestreamTimestamp -> Int
hashWithSalt Int
_salt TimestreamTimestamp' {Text
unit :: Text
value :: Text
$sel:unit:TimestreamTimestamp' :: TimestreamTimestamp -> Text
$sel:value:TimestreamTimestamp' :: TimestreamTimestamp -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
value
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
unit

instance Prelude.NFData TimestreamTimestamp where
  rnf :: TimestreamTimestamp -> ()
rnf TimestreamTimestamp' {Text
unit :: Text
value :: Text
$sel:unit:TimestreamTimestamp' :: TimestreamTimestamp -> Text
$sel:value:TimestreamTimestamp' :: TimestreamTimestamp -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
value seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
unit

instance Data.ToJSON TimestreamTimestamp where
  toJSON :: TimestreamTimestamp -> Value
toJSON TimestreamTimestamp' {Text
unit :: Text
value :: Text
$sel:unit:TimestreamTimestamp' :: TimestreamTimestamp -> Text
$sel:value:TimestreamTimestamp' :: TimestreamTimestamp -> Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"value" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
value),
            forall a. a -> Maybe a
Prelude.Just (Key
"unit" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
unit)
          ]
      )