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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.IoTEvents.Types.Action
import qualified Amazonka.Prelude as Prelude

-- | Specifies the actions performed and the next state entered when a
-- @condition@ evaluates to TRUE.
--
-- /See:/ 'newTransitionEvent' smart constructor.
data TransitionEvent = TransitionEvent'
  { -- | The actions to be performed.
    TransitionEvent -> Maybe [Action]
actions :: Prelude.Maybe [Action],
    -- | The name of the transition event.
    TransitionEvent -> Text
eventName :: Prelude.Text,
    -- | Required. A Boolean expression that when TRUE causes the actions to be
    -- performed and the @nextState@ to be entered.
    TransitionEvent -> Text
condition :: Prelude.Text,
    -- | The next state to enter.
    TransitionEvent -> Text
nextState :: Prelude.Text
  }
  deriving (TransitionEvent -> TransitionEvent -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TransitionEvent -> TransitionEvent -> Bool
$c/= :: TransitionEvent -> TransitionEvent -> Bool
== :: TransitionEvent -> TransitionEvent -> Bool
$c== :: TransitionEvent -> TransitionEvent -> Bool
Prelude.Eq, ReadPrec [TransitionEvent]
ReadPrec TransitionEvent
Int -> ReadS TransitionEvent
ReadS [TransitionEvent]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TransitionEvent]
$creadListPrec :: ReadPrec [TransitionEvent]
readPrec :: ReadPrec TransitionEvent
$creadPrec :: ReadPrec TransitionEvent
readList :: ReadS [TransitionEvent]
$creadList :: ReadS [TransitionEvent]
readsPrec :: Int -> ReadS TransitionEvent
$creadsPrec :: Int -> ReadS TransitionEvent
Prelude.Read, Int -> TransitionEvent -> ShowS
[TransitionEvent] -> ShowS
TransitionEvent -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TransitionEvent] -> ShowS
$cshowList :: [TransitionEvent] -> ShowS
show :: TransitionEvent -> String
$cshow :: TransitionEvent -> String
showsPrec :: Int -> TransitionEvent -> ShowS
$cshowsPrec :: Int -> TransitionEvent -> ShowS
Prelude.Show, forall x. Rep TransitionEvent x -> TransitionEvent
forall x. TransitionEvent -> Rep TransitionEvent x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TransitionEvent x -> TransitionEvent
$cfrom :: forall x. TransitionEvent -> Rep TransitionEvent x
Prelude.Generic)

-- |
-- Create a value of 'TransitionEvent' 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:
--
-- 'actions', 'transitionEvent_actions' - The actions to be performed.
--
-- 'eventName', 'transitionEvent_eventName' - The name of the transition event.
--
-- 'condition', 'transitionEvent_condition' - Required. A Boolean expression that when TRUE causes the actions to be
-- performed and the @nextState@ to be entered.
--
-- 'nextState', 'transitionEvent_nextState' - The next state to enter.
newTransitionEvent ::
  -- | 'eventName'
  Prelude.Text ->
  -- | 'condition'
  Prelude.Text ->
  -- | 'nextState'
  Prelude.Text ->
  TransitionEvent
newTransitionEvent :: Text -> Text -> Text -> TransitionEvent
newTransitionEvent
  Text
pEventName_
  Text
pCondition_
  Text
pNextState_ =
    TransitionEvent'
      { $sel:actions:TransitionEvent' :: Maybe [Action]
actions = forall a. Maybe a
Prelude.Nothing,
        $sel:eventName:TransitionEvent' :: Text
eventName = Text
pEventName_,
        $sel:condition:TransitionEvent' :: Text
condition = Text
pCondition_,
        $sel:nextState:TransitionEvent' :: Text
nextState = Text
pNextState_
      }

-- | The actions to be performed.
transitionEvent_actions :: Lens.Lens' TransitionEvent (Prelude.Maybe [Action])
transitionEvent_actions :: Lens' TransitionEvent (Maybe [Action])
transitionEvent_actions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TransitionEvent' {Maybe [Action]
actions :: Maybe [Action]
$sel:actions:TransitionEvent' :: TransitionEvent -> Maybe [Action]
actions} -> Maybe [Action]
actions) (\s :: TransitionEvent
s@TransitionEvent' {} Maybe [Action]
a -> TransitionEvent
s {$sel:actions:TransitionEvent' :: Maybe [Action]
actions = Maybe [Action]
a} :: TransitionEvent) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The name of the transition event.
transitionEvent_eventName :: Lens.Lens' TransitionEvent Prelude.Text
transitionEvent_eventName :: Lens' TransitionEvent Text
transitionEvent_eventName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TransitionEvent' {Text
eventName :: Text
$sel:eventName:TransitionEvent' :: TransitionEvent -> Text
eventName} -> Text
eventName) (\s :: TransitionEvent
s@TransitionEvent' {} Text
a -> TransitionEvent
s {$sel:eventName:TransitionEvent' :: Text
eventName = Text
a} :: TransitionEvent)

-- | Required. A Boolean expression that when TRUE causes the actions to be
-- performed and the @nextState@ to be entered.
transitionEvent_condition :: Lens.Lens' TransitionEvent Prelude.Text
transitionEvent_condition :: Lens' TransitionEvent Text
transitionEvent_condition = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TransitionEvent' {Text
condition :: Text
$sel:condition:TransitionEvent' :: TransitionEvent -> Text
condition} -> Text
condition) (\s :: TransitionEvent
s@TransitionEvent' {} Text
a -> TransitionEvent
s {$sel:condition:TransitionEvent' :: Text
condition = Text
a} :: TransitionEvent)

-- | The next state to enter.
transitionEvent_nextState :: Lens.Lens' TransitionEvent Prelude.Text
transitionEvent_nextState :: Lens' TransitionEvent Text
transitionEvent_nextState = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TransitionEvent' {Text
nextState :: Text
$sel:nextState:TransitionEvent' :: TransitionEvent -> Text
nextState} -> Text
nextState) (\s :: TransitionEvent
s@TransitionEvent' {} Text
a -> TransitionEvent
s {$sel:nextState:TransitionEvent' :: Text
nextState = Text
a} :: TransitionEvent)

instance Data.FromJSON TransitionEvent where
  parseJSON :: Value -> Parser TransitionEvent
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"TransitionEvent"
      ( \Object
x ->
          Maybe [Action] -> Text -> Text -> Text -> TransitionEvent
TransitionEvent'
            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
"actions" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            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
"eventName")
            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
"condition")
            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
"nextState")
      )

instance Prelude.Hashable TransitionEvent where
  hashWithSalt :: Int -> TransitionEvent -> Int
hashWithSalt Int
_salt TransitionEvent' {Maybe [Action]
Text
nextState :: Text
condition :: Text
eventName :: Text
actions :: Maybe [Action]
$sel:nextState:TransitionEvent' :: TransitionEvent -> Text
$sel:condition:TransitionEvent' :: TransitionEvent -> Text
$sel:eventName:TransitionEvent' :: TransitionEvent -> Text
$sel:actions:TransitionEvent' :: TransitionEvent -> Maybe [Action]
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Action]
actions
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
eventName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
condition
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
nextState

instance Prelude.NFData TransitionEvent where
  rnf :: TransitionEvent -> ()
rnf TransitionEvent' {Maybe [Action]
Text
nextState :: Text
condition :: Text
eventName :: Text
actions :: Maybe [Action]
$sel:nextState:TransitionEvent' :: TransitionEvent -> Text
$sel:condition:TransitionEvent' :: TransitionEvent -> Text
$sel:eventName:TransitionEvent' :: TransitionEvent -> Text
$sel:actions:TransitionEvent' :: TransitionEvent -> Maybe [Action]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [Action]
actions
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
eventName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
condition
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
nextState

instance Data.ToJSON TransitionEvent where
  toJSON :: TransitionEvent -> Value
toJSON TransitionEvent' {Maybe [Action]
Text
nextState :: Text
condition :: Text
eventName :: Text
actions :: Maybe [Action]
$sel:nextState:TransitionEvent' :: TransitionEvent -> Text
$sel:condition:TransitionEvent' :: TransitionEvent -> Text
$sel:eventName:TransitionEvent' :: TransitionEvent -> Text
$sel:actions:TransitionEvent' :: TransitionEvent -> Maybe [Action]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"actions" 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 [Action]
actions,
            forall a. a -> Maybe a
Prelude.Just (Key
"eventName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
eventName),
            forall a. a -> Maybe a
Prelude.Just (Key
"condition" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
condition),
            forall a. a -> Maybe a
Prelude.Just (Key
"nextState" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
nextState)
          ]
      )