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

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

-- | When exiting this state, perform these @actions@ if the specified
-- @condition@ is @TRUE@.
--
-- /See:/ 'newOnExitLifecycle' smart constructor.
data OnExitLifecycle = OnExitLifecycle'
  { -- | Specifies the @actions@ that are performed when the state is exited and
    -- the @condition@ is @TRUE@.
    OnExitLifecycle -> Maybe [Event]
events :: Prelude.Maybe [Event]
  }
  deriving (OnExitLifecycle -> OnExitLifecycle -> Bool
(OnExitLifecycle -> OnExitLifecycle -> Bool)
-> (OnExitLifecycle -> OnExitLifecycle -> Bool)
-> Eq OnExitLifecycle
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OnExitLifecycle -> OnExitLifecycle -> Bool
$c/= :: OnExitLifecycle -> OnExitLifecycle -> Bool
== :: OnExitLifecycle -> OnExitLifecycle -> Bool
$c== :: OnExitLifecycle -> OnExitLifecycle -> Bool
Prelude.Eq, ReadPrec [OnExitLifecycle]
ReadPrec OnExitLifecycle
Int -> ReadS OnExitLifecycle
ReadS [OnExitLifecycle]
(Int -> ReadS OnExitLifecycle)
-> ReadS [OnExitLifecycle]
-> ReadPrec OnExitLifecycle
-> ReadPrec [OnExitLifecycle]
-> Read OnExitLifecycle
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [OnExitLifecycle]
$creadListPrec :: ReadPrec [OnExitLifecycle]
readPrec :: ReadPrec OnExitLifecycle
$creadPrec :: ReadPrec OnExitLifecycle
readList :: ReadS [OnExitLifecycle]
$creadList :: ReadS [OnExitLifecycle]
readsPrec :: Int -> ReadS OnExitLifecycle
$creadsPrec :: Int -> ReadS OnExitLifecycle
Prelude.Read, Int -> OnExitLifecycle -> ShowS
[OnExitLifecycle] -> ShowS
OnExitLifecycle -> String
(Int -> OnExitLifecycle -> ShowS)
-> (OnExitLifecycle -> String)
-> ([OnExitLifecycle] -> ShowS)
-> Show OnExitLifecycle
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OnExitLifecycle] -> ShowS
$cshowList :: [OnExitLifecycle] -> ShowS
show :: OnExitLifecycle -> String
$cshow :: OnExitLifecycle -> String
showsPrec :: Int -> OnExitLifecycle -> ShowS
$cshowsPrec :: Int -> OnExitLifecycle -> ShowS
Prelude.Show, (forall x. OnExitLifecycle -> Rep OnExitLifecycle x)
-> (forall x. Rep OnExitLifecycle x -> OnExitLifecycle)
-> Generic OnExitLifecycle
forall x. Rep OnExitLifecycle x -> OnExitLifecycle
forall x. OnExitLifecycle -> Rep OnExitLifecycle x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep OnExitLifecycle x -> OnExitLifecycle
$cfrom :: forall x. OnExitLifecycle -> Rep OnExitLifecycle x
Prelude.Generic)

-- |
-- Create a value of 'OnExitLifecycle' 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', 'onExitLifecycle_events' - Specifies the @actions@ that are performed when the state is exited and
-- the @condition@ is @TRUE@.
newOnExitLifecycle ::
  OnExitLifecycle
newOnExitLifecycle :: OnExitLifecycle
newOnExitLifecycle =
  OnExitLifecycle' :: Maybe [Event] -> OnExitLifecycle
OnExitLifecycle' {$sel:events:OnExitLifecycle' :: Maybe [Event]
events = Maybe [Event]
forall a. Maybe a
Prelude.Nothing}

-- | Specifies the @actions@ that are performed when the state is exited and
-- the @condition@ is @TRUE@.
onExitLifecycle_events :: Lens.Lens' OnExitLifecycle (Prelude.Maybe [Event])
onExitLifecycle_events :: (Maybe [Event] -> f (Maybe [Event]))
-> OnExitLifecycle -> f OnExitLifecycle
onExitLifecycle_events = (OnExitLifecycle -> Maybe [Event])
-> (OnExitLifecycle -> Maybe [Event] -> OnExitLifecycle)
-> Lens
     OnExitLifecycle OnExitLifecycle (Maybe [Event]) (Maybe [Event])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OnExitLifecycle' {Maybe [Event]
events :: Maybe [Event]
$sel:events:OnExitLifecycle' :: OnExitLifecycle -> Maybe [Event]
events} -> Maybe [Event]
events) (\s :: OnExitLifecycle
s@OnExitLifecycle' {} Maybe [Event]
a -> OnExitLifecycle
s {$sel:events:OnExitLifecycle' :: Maybe [Event]
events = Maybe [Event]
a} :: OnExitLifecycle) ((Maybe [Event] -> f (Maybe [Event]))
 -> OnExitLifecycle -> f OnExitLifecycle)
-> ((Maybe [Event] -> f (Maybe [Event]))
    -> Maybe [Event] -> f (Maybe [Event]))
-> (Maybe [Event] -> f (Maybe [Event]))
-> OnExitLifecycle
-> f OnExitLifecycle
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

instance Core.FromJSON OnExitLifecycle where
  parseJSON :: Value -> Parser OnExitLifecycle
parseJSON =
    String
-> (Object -> Parser OnExitLifecycle)
-> Value
-> Parser OnExitLifecycle
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"OnExitLifecycle"
      ( \Object
x ->
          Maybe [Event] -> OnExitLifecycle
OnExitLifecycle'
            (Maybe [Event] -> OnExitLifecycle)
-> Parser (Maybe [Event]) -> Parser OnExitLifecycle
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)
      )

instance Prelude.Hashable OnExitLifecycle

instance Prelude.NFData OnExitLifecycle

instance Core.ToJSON OnExitLifecycle where
  toJSON :: OnExitLifecycle -> Value
toJSON OnExitLifecycle' {Maybe [Event]
events :: Maybe [Event]
$sel:events:OnExitLifecycle' :: OnExitLifecycle -> 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]
      )