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

import qualified Amazonka.Core as Core
import Amazonka.IoTEvents.Types.Action
import qualified Amazonka.Lens as Lens
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
(TransitionEvent -> TransitionEvent -> Bool)
-> (TransitionEvent -> TransitionEvent -> Bool)
-> Eq TransitionEvent
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]
(Int -> ReadS TransitionEvent)
-> ReadS [TransitionEvent]
-> ReadPrec TransitionEvent
-> ReadPrec [TransitionEvent]
-> Read 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
(Int -> TransitionEvent -> ShowS)
-> (TransitionEvent -> String)
-> ([TransitionEvent] -> ShowS)
-> Show TransitionEvent
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. TransitionEvent -> Rep TransitionEvent x)
-> (forall x. Rep TransitionEvent x -> TransitionEvent)
-> Generic TransitionEvent
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' :: Maybe [Action] -> Text -> Text -> Text -> TransitionEvent
TransitionEvent'
      { $sel:actions:TransitionEvent' :: Maybe [Action]
actions = Maybe [Action]
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 :: (Maybe [Action] -> f (Maybe [Action]))
-> TransitionEvent -> f TransitionEvent
transitionEvent_actions = (TransitionEvent -> Maybe [Action])
-> (TransitionEvent -> Maybe [Action] -> TransitionEvent)
-> Lens
     TransitionEvent TransitionEvent (Maybe [Action]) (Maybe [Action])
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) ((Maybe [Action] -> f (Maybe [Action]))
 -> TransitionEvent -> f TransitionEvent)
-> ((Maybe [Action] -> f (Maybe [Action]))
    -> Maybe [Action] -> f (Maybe [Action]))
-> (Maybe [Action] -> f (Maybe [Action]))
-> TransitionEvent
-> f TransitionEvent
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Action] [Action] [Action] [Action]
-> Iso
     (Maybe [Action]) (Maybe [Action]) (Maybe [Action]) (Maybe [Action])
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 AnIso [Action] [Action] [Action] [Action]
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 :: (Text -> f Text) -> TransitionEvent -> f TransitionEvent
transitionEvent_eventName = (TransitionEvent -> Text)
-> (TransitionEvent -> Text -> TransitionEvent)
-> Lens TransitionEvent TransitionEvent Text Text
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 :: (Text -> f Text) -> TransitionEvent -> f TransitionEvent
transitionEvent_condition = (TransitionEvent -> Text)
-> (TransitionEvent -> Text -> TransitionEvent)
-> Lens TransitionEvent TransitionEvent Text Text
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 :: (Text -> f Text) -> TransitionEvent -> f TransitionEvent
transitionEvent_nextState = (TransitionEvent -> Text)
-> (TransitionEvent -> Text -> TransitionEvent)
-> Lens TransitionEvent TransitionEvent Text Text
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 Core.FromJSON TransitionEvent where
  parseJSON :: Value -> Parser TransitionEvent
parseJSON =
    String
-> (Object -> Parser TransitionEvent)
-> Value
-> Parser TransitionEvent
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"TransitionEvent"
      ( \Object
x ->
          Maybe [Action] -> Text -> Text -> Text -> TransitionEvent
TransitionEvent'
            (Maybe [Action] -> Text -> Text -> Text -> TransitionEvent)
-> Parser (Maybe [Action])
-> Parser (Text -> Text -> Text -> TransitionEvent)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [Action]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"actions" Parser (Maybe (Maybe [Action]))
-> Maybe [Action] -> Parser (Maybe [Action])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Action]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Text -> Text -> Text -> TransitionEvent)
-> Parser Text -> Parser (Text -> Text -> TransitionEvent)
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
"eventName")
            Parser (Text -> Text -> TransitionEvent)
-> Parser Text -> Parser (Text -> TransitionEvent)
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
"condition")
            Parser (Text -> TransitionEvent)
-> Parser Text -> Parser TransitionEvent
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
"nextState")
      )

instance Prelude.Hashable TransitionEvent

instance Prelude.NFData TransitionEvent

instance Core.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
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"actions" Text -> [Action] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([Action] -> Pair) -> Maybe [Action] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Action]
actions,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"eventName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
eventName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"condition" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
condition),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"nextState" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
nextState)
          ]
      )