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

import qualified Amazonka.Core as Core
import Amazonka.IoTEvents.Types.Event
import Amazonka.IoTEvents.Types.TransitionEvent
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Specifies the actions performed when the @condition@ evaluates to TRUE.
--
-- /See:/ 'newOnInputLifecycle' smart constructor.
data OnInputLifecycle = OnInputLifecycle'
  { -- | Specifies the actions performed when the @condition@ evaluates to TRUE.
    OnInputLifecycle -> Maybe [Event]
events :: Prelude.Maybe [Event],
    -- | Specifies the actions performed, and the next state entered, when a
    -- @condition@ evaluates to TRUE.
    OnInputLifecycle -> Maybe [TransitionEvent]
transitionEvents :: Prelude.Maybe [TransitionEvent]
  }
  deriving (OnInputLifecycle -> OnInputLifecycle -> Bool
(OnInputLifecycle -> OnInputLifecycle -> Bool)
-> (OnInputLifecycle -> OnInputLifecycle -> Bool)
-> Eq OnInputLifecycle
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OnInputLifecycle -> OnInputLifecycle -> Bool
$c/= :: OnInputLifecycle -> OnInputLifecycle -> Bool
== :: OnInputLifecycle -> OnInputLifecycle -> Bool
$c== :: OnInputLifecycle -> OnInputLifecycle -> Bool
Prelude.Eq, ReadPrec [OnInputLifecycle]
ReadPrec OnInputLifecycle
Int -> ReadS OnInputLifecycle
ReadS [OnInputLifecycle]
(Int -> ReadS OnInputLifecycle)
-> ReadS [OnInputLifecycle]
-> ReadPrec OnInputLifecycle
-> ReadPrec [OnInputLifecycle]
-> Read OnInputLifecycle
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [OnInputLifecycle]
$creadListPrec :: ReadPrec [OnInputLifecycle]
readPrec :: ReadPrec OnInputLifecycle
$creadPrec :: ReadPrec OnInputLifecycle
readList :: ReadS [OnInputLifecycle]
$creadList :: ReadS [OnInputLifecycle]
readsPrec :: Int -> ReadS OnInputLifecycle
$creadsPrec :: Int -> ReadS OnInputLifecycle
Prelude.Read, Int -> OnInputLifecycle -> ShowS
[OnInputLifecycle] -> ShowS
OnInputLifecycle -> String
(Int -> OnInputLifecycle -> ShowS)
-> (OnInputLifecycle -> String)
-> ([OnInputLifecycle] -> ShowS)
-> Show OnInputLifecycle
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OnInputLifecycle] -> ShowS
$cshowList :: [OnInputLifecycle] -> ShowS
show :: OnInputLifecycle -> String
$cshow :: OnInputLifecycle -> String
showsPrec :: Int -> OnInputLifecycle -> ShowS
$cshowsPrec :: Int -> OnInputLifecycle -> ShowS
Prelude.Show, (forall x. OnInputLifecycle -> Rep OnInputLifecycle x)
-> (forall x. Rep OnInputLifecycle x -> OnInputLifecycle)
-> Generic OnInputLifecycle
forall x. Rep OnInputLifecycle x -> OnInputLifecycle
forall x. OnInputLifecycle -> Rep OnInputLifecycle x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep OnInputLifecycle x -> OnInputLifecycle
$cfrom :: forall x. OnInputLifecycle -> Rep OnInputLifecycle x
Prelude.Generic)

-- |
-- Create a value of 'OnInputLifecycle' 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:
--
-- 'events', 'onInputLifecycle_events' - Specifies the actions performed when the @condition@ evaluates to TRUE.
--
-- 'transitionEvents', 'onInputLifecycle_transitionEvents' - Specifies the actions performed, and the next state entered, when a
-- @condition@ evaluates to TRUE.
newOnInputLifecycle ::
  OnInputLifecycle
newOnInputLifecycle :: OnInputLifecycle
newOnInputLifecycle =
  OnInputLifecycle' :: Maybe [Event] -> Maybe [TransitionEvent] -> OnInputLifecycle
OnInputLifecycle'
    { $sel:events:OnInputLifecycle' :: Maybe [Event]
events = Maybe [Event]
forall a. Maybe a
Prelude.Nothing,
      $sel:transitionEvents:OnInputLifecycle' :: Maybe [TransitionEvent]
transitionEvents = Maybe [TransitionEvent]
forall a. Maybe a
Prelude.Nothing
    }

-- | Specifies the actions performed when the @condition@ evaluates to TRUE.
onInputLifecycle_events :: Lens.Lens' OnInputLifecycle (Prelude.Maybe [Event])
onInputLifecycle_events :: (Maybe [Event] -> f (Maybe [Event]))
-> OnInputLifecycle -> f OnInputLifecycle
onInputLifecycle_events = (OnInputLifecycle -> Maybe [Event])
-> (OnInputLifecycle -> Maybe [Event] -> OnInputLifecycle)
-> Lens
     OnInputLifecycle OnInputLifecycle (Maybe [Event]) (Maybe [Event])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OnInputLifecycle' {Maybe [Event]
events :: Maybe [Event]
$sel:events:OnInputLifecycle' :: OnInputLifecycle -> Maybe [Event]
events} -> Maybe [Event]
events) (\s :: OnInputLifecycle
s@OnInputLifecycle' {} Maybe [Event]
a -> OnInputLifecycle
s {$sel:events:OnInputLifecycle' :: Maybe [Event]
events = Maybe [Event]
a} :: OnInputLifecycle) ((Maybe [Event] -> f (Maybe [Event]))
 -> OnInputLifecycle -> f OnInputLifecycle)
-> ((Maybe [Event] -> f (Maybe [Event]))
    -> Maybe [Event] -> f (Maybe [Event]))
-> (Maybe [Event] -> f (Maybe [Event]))
-> OnInputLifecycle
-> f OnInputLifecycle
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Event] [Event] [Event] [Event]
-> Iso
     (Maybe [Event]) (Maybe [Event]) (Maybe [Event]) (Maybe [Event])
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 [Event] [Event] [Event] [Event]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Specifies the actions performed, and the next state entered, when a
-- @condition@ evaluates to TRUE.
onInputLifecycle_transitionEvents :: Lens.Lens' OnInputLifecycle (Prelude.Maybe [TransitionEvent])
onInputLifecycle_transitionEvents :: (Maybe [TransitionEvent] -> f (Maybe [TransitionEvent]))
-> OnInputLifecycle -> f OnInputLifecycle
onInputLifecycle_transitionEvents = (OnInputLifecycle -> Maybe [TransitionEvent])
-> (OnInputLifecycle
    -> Maybe [TransitionEvent] -> OnInputLifecycle)
-> Lens
     OnInputLifecycle
     OnInputLifecycle
     (Maybe [TransitionEvent])
     (Maybe [TransitionEvent])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OnInputLifecycle' {Maybe [TransitionEvent]
transitionEvents :: Maybe [TransitionEvent]
$sel:transitionEvents:OnInputLifecycle' :: OnInputLifecycle -> Maybe [TransitionEvent]
transitionEvents} -> Maybe [TransitionEvent]
transitionEvents) (\s :: OnInputLifecycle
s@OnInputLifecycle' {} Maybe [TransitionEvent]
a -> OnInputLifecycle
s {$sel:transitionEvents:OnInputLifecycle' :: Maybe [TransitionEvent]
transitionEvents = Maybe [TransitionEvent]
a} :: OnInputLifecycle) ((Maybe [TransitionEvent] -> f (Maybe [TransitionEvent]))
 -> OnInputLifecycle -> f OnInputLifecycle)
-> ((Maybe [TransitionEvent] -> f (Maybe [TransitionEvent]))
    -> Maybe [TransitionEvent] -> f (Maybe [TransitionEvent]))
-> (Maybe [TransitionEvent] -> f (Maybe [TransitionEvent]))
-> OnInputLifecycle
-> f OnInputLifecycle
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [TransitionEvent]
  [TransitionEvent]
  [TransitionEvent]
  [TransitionEvent]
-> Iso
     (Maybe [TransitionEvent])
     (Maybe [TransitionEvent])
     (Maybe [TransitionEvent])
     (Maybe [TransitionEvent])
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
  [TransitionEvent]
  [TransitionEvent]
  [TransitionEvent]
  [TransitionEvent]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON OnInputLifecycle where
  parseJSON :: Value -> Parser OnInputLifecycle
parseJSON =
    String
-> (Object -> Parser OnInputLifecycle)
-> Value
-> Parser OnInputLifecycle
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"OnInputLifecycle"
      ( \Object
x ->
          Maybe [Event] -> Maybe [TransitionEvent] -> OnInputLifecycle
OnInputLifecycle'
            (Maybe [Event] -> Maybe [TransitionEvent] -> OnInputLifecycle)
-> Parser (Maybe [Event])
-> Parser (Maybe [TransitionEvent] -> OnInputLifecycle)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [Event]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"events" Parser (Maybe (Maybe [Event]))
-> Maybe [Event] -> Parser (Maybe [Event])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [Event]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe [TransitionEvent] -> OnInputLifecycle)
-> Parser (Maybe [TransitionEvent]) -> Parser OnInputLifecycle
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x Object -> Text -> Parser (Maybe (Maybe [TransitionEvent]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"transitionEvents"
                            Parser (Maybe (Maybe [TransitionEvent]))
-> Maybe [TransitionEvent] -> Parser (Maybe [TransitionEvent])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [TransitionEvent]
forall a. Monoid a => a
Prelude.mempty
                        )
      )

instance Prelude.Hashable OnInputLifecycle

instance Prelude.NFData OnInputLifecycle

instance Core.ToJSON OnInputLifecycle where
  toJSON :: OnInputLifecycle -> Value
toJSON OnInputLifecycle' {Maybe [Event]
Maybe [TransitionEvent]
transitionEvents :: Maybe [TransitionEvent]
events :: Maybe [Event]
$sel:transitionEvents:OnInputLifecycle' :: OnInputLifecycle -> Maybe [TransitionEvent]
$sel:events:OnInputLifecycle' :: OnInputLifecycle -> Maybe [Event]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"events" Text -> [Event] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([Event] -> Pair) -> Maybe [Event] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Event]
events,
            (Text
"transitionEvents" Text -> [TransitionEvent] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              ([TransitionEvent] -> Pair)
-> Maybe [TransitionEvent] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [TransitionEvent]
transitionEvents
          ]
      )