{-# 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.SetTimerAction
-- 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.SetTimerAction where

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

-- | Information needed to set the timer.
--
-- /See:/ 'newSetTimerAction' smart constructor.
data SetTimerAction = SetTimerAction'
  { -- | The duration of the timer, in seconds. You can use a string expression
    -- that includes numbers, variables (@$variable.\<variable-name>@), and
    -- input values (@$input.\<input-name>.\<path-to-datum>@) as the duration.
    -- The range of the duration is 1-31622400 seconds. To ensure accuracy, the
    -- minimum duration is 60 seconds. The evaluated result of the duration is
    -- rounded down to the nearest whole number.
    SetTimerAction -> Maybe Text
durationExpression :: Prelude.Maybe Prelude.Text,
    -- | The number of seconds until the timer expires. The minimum value is 60
    -- seconds to ensure accuracy. The maximum value is 31622400 seconds.
    SetTimerAction -> Maybe Natural
seconds :: Prelude.Maybe Prelude.Natural,
    -- | The name of the timer.
    SetTimerAction -> Text
timerName :: Prelude.Text
  }
  deriving (SetTimerAction -> SetTimerAction -> Bool
(SetTimerAction -> SetTimerAction -> Bool)
-> (SetTimerAction -> SetTimerAction -> Bool) -> Eq SetTimerAction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SetTimerAction -> SetTimerAction -> Bool
$c/= :: SetTimerAction -> SetTimerAction -> Bool
== :: SetTimerAction -> SetTimerAction -> Bool
$c== :: SetTimerAction -> SetTimerAction -> Bool
Prelude.Eq, ReadPrec [SetTimerAction]
ReadPrec SetTimerAction
Int -> ReadS SetTimerAction
ReadS [SetTimerAction]
(Int -> ReadS SetTimerAction)
-> ReadS [SetTimerAction]
-> ReadPrec SetTimerAction
-> ReadPrec [SetTimerAction]
-> Read SetTimerAction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SetTimerAction]
$creadListPrec :: ReadPrec [SetTimerAction]
readPrec :: ReadPrec SetTimerAction
$creadPrec :: ReadPrec SetTimerAction
readList :: ReadS [SetTimerAction]
$creadList :: ReadS [SetTimerAction]
readsPrec :: Int -> ReadS SetTimerAction
$creadsPrec :: Int -> ReadS SetTimerAction
Prelude.Read, Int -> SetTimerAction -> ShowS
[SetTimerAction] -> ShowS
SetTimerAction -> String
(Int -> SetTimerAction -> ShowS)
-> (SetTimerAction -> String)
-> ([SetTimerAction] -> ShowS)
-> Show SetTimerAction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SetTimerAction] -> ShowS
$cshowList :: [SetTimerAction] -> ShowS
show :: SetTimerAction -> String
$cshow :: SetTimerAction -> String
showsPrec :: Int -> SetTimerAction -> ShowS
$cshowsPrec :: Int -> SetTimerAction -> ShowS
Prelude.Show, (forall x. SetTimerAction -> Rep SetTimerAction x)
-> (forall x. Rep SetTimerAction x -> SetTimerAction)
-> Generic SetTimerAction
forall x. Rep SetTimerAction x -> SetTimerAction
forall x. SetTimerAction -> Rep SetTimerAction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SetTimerAction x -> SetTimerAction
$cfrom :: forall x. SetTimerAction -> Rep SetTimerAction x
Prelude.Generic)

-- |
-- Create a value of 'SetTimerAction' 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:
--
-- 'durationExpression', 'setTimerAction_durationExpression' - The duration of the timer, in seconds. You can use a string expression
-- that includes numbers, variables (@$variable.\<variable-name>@), and
-- input values (@$input.\<input-name>.\<path-to-datum>@) as the duration.
-- The range of the duration is 1-31622400 seconds. To ensure accuracy, the
-- minimum duration is 60 seconds. The evaluated result of the duration is
-- rounded down to the nearest whole number.
--
-- 'seconds', 'setTimerAction_seconds' - The number of seconds until the timer expires. The minimum value is 60
-- seconds to ensure accuracy. The maximum value is 31622400 seconds.
--
-- 'timerName', 'setTimerAction_timerName' - The name of the timer.
newSetTimerAction ::
  -- | 'timerName'
  Prelude.Text ->
  SetTimerAction
newSetTimerAction :: Text -> SetTimerAction
newSetTimerAction Text
pTimerName_ =
  SetTimerAction' :: Maybe Text -> Maybe Natural -> Text -> SetTimerAction
SetTimerAction'
    { $sel:durationExpression:SetTimerAction' :: Maybe Text
durationExpression =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:seconds:SetTimerAction' :: Maybe Natural
seconds = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:timerName:SetTimerAction' :: Text
timerName = Text
pTimerName_
    }

-- | The duration of the timer, in seconds. You can use a string expression
-- that includes numbers, variables (@$variable.\<variable-name>@), and
-- input values (@$input.\<input-name>.\<path-to-datum>@) as the duration.
-- The range of the duration is 1-31622400 seconds. To ensure accuracy, the
-- minimum duration is 60 seconds. The evaluated result of the duration is
-- rounded down to the nearest whole number.
setTimerAction_durationExpression :: Lens.Lens' SetTimerAction (Prelude.Maybe Prelude.Text)
setTimerAction_durationExpression :: (Maybe Text -> f (Maybe Text))
-> SetTimerAction -> f SetTimerAction
setTimerAction_durationExpression = (SetTimerAction -> Maybe Text)
-> (SetTimerAction -> Maybe Text -> SetTimerAction)
-> Lens SetTimerAction SetTimerAction (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SetTimerAction' {Maybe Text
durationExpression :: Maybe Text
$sel:durationExpression:SetTimerAction' :: SetTimerAction -> Maybe Text
durationExpression} -> Maybe Text
durationExpression) (\s :: SetTimerAction
s@SetTimerAction' {} Maybe Text
a -> SetTimerAction
s {$sel:durationExpression:SetTimerAction' :: Maybe Text
durationExpression = Maybe Text
a} :: SetTimerAction)

-- | The number of seconds until the timer expires. The minimum value is 60
-- seconds to ensure accuracy. The maximum value is 31622400 seconds.
setTimerAction_seconds :: Lens.Lens' SetTimerAction (Prelude.Maybe Prelude.Natural)
setTimerAction_seconds :: (Maybe Natural -> f (Maybe Natural))
-> SetTimerAction -> f SetTimerAction
setTimerAction_seconds = (SetTimerAction -> Maybe Natural)
-> (SetTimerAction -> Maybe Natural -> SetTimerAction)
-> Lens
     SetTimerAction SetTimerAction (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SetTimerAction' {Maybe Natural
seconds :: Maybe Natural
$sel:seconds:SetTimerAction' :: SetTimerAction -> Maybe Natural
seconds} -> Maybe Natural
seconds) (\s :: SetTimerAction
s@SetTimerAction' {} Maybe Natural
a -> SetTimerAction
s {$sel:seconds:SetTimerAction' :: Maybe Natural
seconds = Maybe Natural
a} :: SetTimerAction)

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

instance Core.FromJSON SetTimerAction where
  parseJSON :: Value -> Parser SetTimerAction
parseJSON =
    String
-> (Object -> Parser SetTimerAction)
-> Value
-> Parser SetTimerAction
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"SetTimerAction"
      ( \Object
x ->
          Maybe Text -> Maybe Natural -> Text -> SetTimerAction
SetTimerAction'
            (Maybe Text -> Maybe Natural -> Text -> SetTimerAction)
-> Parser (Maybe Text)
-> Parser (Maybe Natural -> Text -> SetTimerAction)
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
"durationExpression")
            Parser (Maybe Natural -> Text -> SetTimerAction)
-> Parser (Maybe Natural) -> Parser (Text -> SetTimerAction)
forall (f :: * -> *) a b. Applicative f => 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
"seconds")
            Parser (Text -> SetTimerAction)
-> Parser Text -> Parser SetTimerAction
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
"timerName")
      )

instance Prelude.Hashable SetTimerAction

instance Prelude.NFData SetTimerAction

instance Core.ToJSON SetTimerAction where
  toJSON :: SetTimerAction -> Value
toJSON SetTimerAction' {Maybe Natural
Maybe Text
Text
timerName :: Text
seconds :: Maybe Natural
durationExpression :: Maybe Text
$sel:timerName:SetTimerAction' :: SetTimerAction -> Text
$sel:seconds:SetTimerAction' :: SetTimerAction -> Maybe Natural
$sel:durationExpression:SetTimerAction' :: SetTimerAction -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"durationExpression" 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
durationExpression,
            (Text
"seconds" 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
seconds,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"timerName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
timerName)
          ]
      )