{-# 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.IoTSiteWise.Types.TimeInNanos
-- 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.IoTSiteWise.Types.TimeInNanos where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Contains a timestamp with optional nanosecond granularity.
--
-- /See:/ 'newTimeInNanos' smart constructor.
data TimeInNanos = TimeInNanos'
  { -- | The nanosecond offset from @timeInSeconds@.
    TimeInNanos -> Maybe Natural
offsetInNanos :: Prelude.Maybe Prelude.Natural,
    -- | The timestamp date, in seconds, in the Unix epoch format. Fractional
    -- nanosecond data is provided by @offsetInNanos@.
    TimeInNanos -> Natural
timeInSeconds :: Prelude.Natural
  }
  deriving (TimeInNanos -> TimeInNanos -> Bool
(TimeInNanos -> TimeInNanos -> Bool)
-> (TimeInNanos -> TimeInNanos -> Bool) -> Eq TimeInNanos
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TimeInNanos -> TimeInNanos -> Bool
$c/= :: TimeInNanos -> TimeInNanos -> Bool
== :: TimeInNanos -> TimeInNanos -> Bool
$c== :: TimeInNanos -> TimeInNanos -> Bool
Prelude.Eq, ReadPrec [TimeInNanos]
ReadPrec TimeInNanos
Int -> ReadS TimeInNanos
ReadS [TimeInNanos]
(Int -> ReadS TimeInNanos)
-> ReadS [TimeInNanos]
-> ReadPrec TimeInNanos
-> ReadPrec [TimeInNanos]
-> Read TimeInNanos
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TimeInNanos]
$creadListPrec :: ReadPrec [TimeInNanos]
readPrec :: ReadPrec TimeInNanos
$creadPrec :: ReadPrec TimeInNanos
readList :: ReadS [TimeInNanos]
$creadList :: ReadS [TimeInNanos]
readsPrec :: Int -> ReadS TimeInNanos
$creadsPrec :: Int -> ReadS TimeInNanos
Prelude.Read, Int -> TimeInNanos -> ShowS
[TimeInNanos] -> ShowS
TimeInNanos -> String
(Int -> TimeInNanos -> ShowS)
-> (TimeInNanos -> String)
-> ([TimeInNanos] -> ShowS)
-> Show TimeInNanos
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TimeInNanos] -> ShowS
$cshowList :: [TimeInNanos] -> ShowS
show :: TimeInNanos -> String
$cshow :: TimeInNanos -> String
showsPrec :: Int -> TimeInNanos -> ShowS
$cshowsPrec :: Int -> TimeInNanos -> ShowS
Prelude.Show, (forall x. TimeInNanos -> Rep TimeInNanos x)
-> (forall x. Rep TimeInNanos x -> TimeInNanos)
-> Generic TimeInNanos
forall x. Rep TimeInNanos x -> TimeInNanos
forall x. TimeInNanos -> Rep TimeInNanos x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TimeInNanos x -> TimeInNanos
$cfrom :: forall x. TimeInNanos -> Rep TimeInNanos x
Prelude.Generic)

-- |
-- Create a value of 'TimeInNanos' 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', 'timeInNanos_offsetInNanos' - The nanosecond offset from @timeInSeconds@.
--
-- 'timeInSeconds', 'timeInNanos_timeInSeconds' - The timestamp date, in seconds, in the Unix epoch format. Fractional
-- nanosecond data is provided by @offsetInNanos@.
newTimeInNanos ::
  -- | 'timeInSeconds'
  Prelude.Natural ->
  TimeInNanos
newTimeInNanos :: Natural -> TimeInNanos
newTimeInNanos Natural
pTimeInSeconds_ =
  TimeInNanos' :: Maybe Natural -> Natural -> TimeInNanos
TimeInNanos'
    { $sel:offsetInNanos:TimeInNanos' :: Maybe Natural
offsetInNanos = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:timeInSeconds:TimeInNanos' :: Natural
timeInSeconds = Natural
pTimeInSeconds_
    }

-- | The nanosecond offset from @timeInSeconds@.
timeInNanos_offsetInNanos :: Lens.Lens' TimeInNanos (Prelude.Maybe Prelude.Natural)
timeInNanos_offsetInNanos :: (Maybe Natural -> f (Maybe Natural))
-> TimeInNanos -> f TimeInNanos
timeInNanos_offsetInNanos = (TimeInNanos -> Maybe Natural)
-> (TimeInNanos -> Maybe Natural -> TimeInNanos)
-> Lens TimeInNanos TimeInNanos (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TimeInNanos' {Maybe Natural
offsetInNanos :: Maybe Natural
$sel:offsetInNanos:TimeInNanos' :: TimeInNanos -> Maybe Natural
offsetInNanos} -> Maybe Natural
offsetInNanos) (\s :: TimeInNanos
s@TimeInNanos' {} Maybe Natural
a -> TimeInNanos
s {$sel:offsetInNanos:TimeInNanos' :: Maybe Natural
offsetInNanos = Maybe Natural
a} :: TimeInNanos)

-- | The timestamp date, in seconds, in the Unix epoch format. Fractional
-- nanosecond data is provided by @offsetInNanos@.
timeInNanos_timeInSeconds :: Lens.Lens' TimeInNanos Prelude.Natural
timeInNanos_timeInSeconds :: (Natural -> f Natural) -> TimeInNanos -> f TimeInNanos
timeInNanos_timeInSeconds = (TimeInNanos -> Natural)
-> (TimeInNanos -> Natural -> TimeInNanos)
-> Lens TimeInNanos TimeInNanos Natural Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TimeInNanos' {Natural
timeInSeconds :: Natural
$sel:timeInSeconds:TimeInNanos' :: TimeInNanos -> Natural
timeInSeconds} -> Natural
timeInSeconds) (\s :: TimeInNanos
s@TimeInNanos' {} Natural
a -> TimeInNanos
s {$sel:timeInSeconds:TimeInNanos' :: Natural
timeInSeconds = Natural
a} :: TimeInNanos)

instance Core.FromJSON TimeInNanos where
  parseJSON :: Value -> Parser TimeInNanos
parseJSON =
    String
-> (Object -> Parser TimeInNanos) -> Value -> Parser TimeInNanos
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"TimeInNanos"
      ( \Object
x ->
          Maybe Natural -> Natural -> TimeInNanos
TimeInNanos'
            (Maybe Natural -> Natural -> TimeInNanos)
-> Parser (Maybe Natural) -> Parser (Natural -> TimeInNanos)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"offsetInNanos")
            Parser (Natural -> TimeInNanos)
-> Parser Natural -> Parser TimeInNanos
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"timeInSeconds")
      )

instance Prelude.Hashable TimeInNanos

instance Prelude.NFData TimeInNanos

instance Core.ToJSON TimeInNanos where
  toJSON :: TimeInNanos -> Value
toJSON TimeInNanos' {Natural
Maybe Natural
timeInSeconds :: Natural
offsetInNanos :: Maybe Natural
$sel:timeInSeconds:TimeInNanos' :: TimeInNanos -> Natural
$sel:offsetInNanos:TimeInNanos' :: TimeInNanos -> Maybe Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"offsetInNanos" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
offsetInNanos,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"timeInSeconds" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
timeInSeconds)
          ]
      )