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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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
(TimestreamTimestamp -> TimestreamTimestamp -> Bool)
-> (TimestreamTimestamp -> TimestreamTimestamp -> Bool)
-> Eq TimestreamTimestamp
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]
(Int -> ReadS TimestreamTimestamp)
-> ReadS [TimestreamTimestamp]
-> ReadPrec TimestreamTimestamp
-> ReadPrec [TimestreamTimestamp]
-> Read 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
(Int -> TimestreamTimestamp -> ShowS)
-> (TimestreamTimestamp -> String)
-> ([TimestreamTimestamp] -> ShowS)
-> Show TimestreamTimestamp
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. TimestreamTimestamp -> Rep TimestreamTimestamp x)
-> (forall x. Rep TimestreamTimestamp x -> TimestreamTimestamp)
-> Generic TimestreamTimestamp
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' :: Text -> Text -> TimestreamTimestamp
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 :: (Text -> f Text) -> TimestreamTimestamp -> f TimestreamTimestamp
timestreamTimestamp_value = (TimestreamTimestamp -> Text)
-> (TimestreamTimestamp -> Text -> TimestreamTimestamp)
-> Lens TimestreamTimestamp TimestreamTimestamp Text Text
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 :: (Text -> f Text) -> TimestreamTimestamp -> f TimestreamTimestamp
timestreamTimestamp_unit = (TimestreamTimestamp -> Text)
-> (TimestreamTimestamp -> Text -> TimestreamTimestamp)
-> Lens TimestreamTimestamp TimestreamTimestamp Text Text
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 Core.FromJSON TimestreamTimestamp where
  parseJSON :: Value -> Parser TimestreamTimestamp
parseJSON =
    String
-> (Object -> Parser TimestreamTimestamp)
-> Value
-> Parser TimestreamTimestamp
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"TimestreamTimestamp"
      ( \Object
x ->
          Text -> Text -> TimestreamTimestamp
TimestreamTimestamp'
            (Text -> Text -> TimestreamTimestamp)
-> Parser Text -> Parser (Text -> TimestreamTimestamp)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"value") Parser (Text -> TimestreamTimestamp)
-> Parser Text -> Parser TimestreamTimestamp
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
"unit")
      )

instance Prelude.Hashable TimestreamTimestamp

instance Prelude.NFData TimestreamTimestamp

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"value" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
value),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"unit" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
unit)
          ]
      )