{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.IoTEvents.Types.SetTimerAction 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

-- | 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
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]
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
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. 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'
    { $sel:durationExpression:SetTimerAction' :: Maybe Text
durationExpression =
        forall a. Maybe a
Prelude.Nothing,
      $sel:seconds:SetTimerAction' :: Maybe Natural
seconds = 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 :: Lens' SetTimerAction (Maybe Text)
setTimerAction_durationExpression = 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 :: Lens' SetTimerAction (Maybe Natural)
setTimerAction_seconds = 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 :: Lens' SetTimerAction Text
setTimerAction_timerName = 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 Data.FromJSON SetTimerAction where
  parseJSON :: Value -> Parser SetTimerAction
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"SetTimerAction"
      ( \Object
x ->
          Maybe Text -> Maybe Natural -> Text -> SetTimerAction
SetTimerAction'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"durationExpression")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"seconds")
            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
"timerName")
      )

instance Prelude.Hashable SetTimerAction where
  hashWithSalt :: Int -> SetTimerAction -> Int
hashWithSalt Int
_salt 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
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
durationExpression
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
seconds
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
timerName

instance Prelude.NFData SetTimerAction where
  rnf :: SetTimerAction -> ()
rnf 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
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
durationExpression
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
seconds
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
timerName

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"durationExpression" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
durationExpression,
            (Key
"seconds" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
seconds,
            forall a. a -> Maybe a
Prelude.Just (Key
"timerName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
timerName)
          ]
      )