{-# 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.IoTEventsData.Types.Timer
-- 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.IoTEventsData.Types.Timer where

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

-- | The current state of a timer.
--
-- /See:/ 'newTimer' smart constructor.
data Timer = Timer'
  { -- | The name of the timer.
    Timer -> Text
name :: Prelude.Text,
    -- | The number of seconds which have elapsed on the timer.
    Timer -> POSIX
timestamp :: Core.POSIX
  }
  deriving (Timer -> Timer -> Bool
(Timer -> Timer -> Bool) -> (Timer -> Timer -> Bool) -> Eq Timer
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Timer -> Timer -> Bool
$c/= :: Timer -> Timer -> Bool
== :: Timer -> Timer -> Bool
$c== :: Timer -> Timer -> Bool
Prelude.Eq, ReadPrec [Timer]
ReadPrec Timer
Int -> ReadS Timer
ReadS [Timer]
(Int -> ReadS Timer)
-> ReadS [Timer]
-> ReadPrec Timer
-> ReadPrec [Timer]
-> Read Timer
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Timer]
$creadListPrec :: ReadPrec [Timer]
readPrec :: ReadPrec Timer
$creadPrec :: ReadPrec Timer
readList :: ReadS [Timer]
$creadList :: ReadS [Timer]
readsPrec :: Int -> ReadS Timer
$creadsPrec :: Int -> ReadS Timer
Prelude.Read, Int -> Timer -> ShowS
[Timer] -> ShowS
Timer -> String
(Int -> Timer -> ShowS)
-> (Timer -> String) -> ([Timer] -> ShowS) -> Show Timer
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Timer] -> ShowS
$cshowList :: [Timer] -> ShowS
show :: Timer -> String
$cshow :: Timer -> String
showsPrec :: Int -> Timer -> ShowS
$cshowsPrec :: Int -> Timer -> ShowS
Prelude.Show, (forall x. Timer -> Rep Timer x)
-> (forall x. Rep Timer x -> Timer) -> Generic Timer
forall x. Rep Timer x -> Timer
forall x. Timer -> Rep Timer x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Timer x -> Timer
$cfrom :: forall x. Timer -> Rep Timer x
Prelude.Generic)

-- |
-- Create a value of 'Timer' 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:
--
-- 'name', 'timer_name' - The name of the timer.
--
-- 'timestamp', 'timer_timestamp' - The number of seconds which have elapsed on the timer.
newTimer ::
  -- | 'name'
  Prelude.Text ->
  -- | 'timestamp'
  Prelude.UTCTime ->
  Timer
newTimer :: Text -> UTCTime -> Timer
newTimer Text
pName_ UTCTime
pTimestamp_ =
  Timer' :: Text -> POSIX -> Timer
Timer'
    { $sel:name:Timer' :: Text
name = Text
pName_,
      $sel:timestamp:Timer' :: POSIX
timestamp = Tagged UTCTime (Identity UTCTime) -> Tagged POSIX (Identity POSIX)
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time (Tagged UTCTime (Identity UTCTime)
 -> Tagged POSIX (Identity POSIX))
-> UTCTime -> POSIX
forall t b. AReview t b -> b -> t
Lens.# UTCTime
pTimestamp_
    }

-- | The name of the timer.
timer_name :: Lens.Lens' Timer Prelude.Text
timer_name :: (Text -> f Text) -> Timer -> f Timer
timer_name = (Timer -> Text)
-> (Timer -> Text -> Timer) -> Lens Timer Timer Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Timer' {Text
name :: Text
$sel:name:Timer' :: Timer -> Text
name} -> Text
name) (\s :: Timer
s@Timer' {} Text
a -> Timer
s {$sel:name:Timer' :: Text
name = Text
a} :: Timer)

-- | The number of seconds which have elapsed on the timer.
timer_timestamp :: Lens.Lens' Timer Prelude.UTCTime
timer_timestamp :: (UTCTime -> f UTCTime) -> Timer -> f Timer
timer_timestamp = (Timer -> POSIX)
-> (Timer -> POSIX -> Timer) -> Lens Timer Timer POSIX POSIX
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Timer' {POSIX
timestamp :: POSIX
$sel:timestamp:Timer' :: Timer -> POSIX
timestamp} -> POSIX
timestamp) (\s :: Timer
s@Timer' {} POSIX
a -> Timer
s {$sel:timestamp:Timer' :: POSIX
timestamp = POSIX
a} :: Timer) ((POSIX -> f POSIX) -> Timer -> f Timer)
-> ((UTCTime -> f UTCTime) -> POSIX -> f POSIX)
-> (UTCTime -> f UTCTime)
-> Timer
-> f Timer
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (UTCTime -> f UTCTime) -> POSIX -> f POSIX
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

instance Core.FromJSON Timer where
  parseJSON :: Value -> Parser Timer
parseJSON =
    String -> (Object -> Parser Timer) -> Value -> Parser Timer
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Timer"
      ( \Object
x ->
          Text -> POSIX -> Timer
Timer'
            (Text -> POSIX -> Timer) -> Parser Text -> Parser (POSIX -> Timer)
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
"name")
            Parser (POSIX -> Timer) -> Parser POSIX -> Parser Timer
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser POSIX
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"timestamp")
      )

instance Prelude.Hashable Timer

instance Prelude.NFData Timer