{-# 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-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.OnExitLifecycle 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.Event
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
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]
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
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. 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' {$sel:events:OnExitLifecycle' :: Maybe [Event]
events = 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 :: Lens' OnExitLifecycle (Maybe [Event])
onExitLifecycle_events = 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) 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

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

instance Prelude.Hashable OnExitLifecycle where
  hashWithSalt :: Int -> OnExitLifecycle -> Int
hashWithSalt Int
_salt OnExitLifecycle' {Maybe [Event]
events :: Maybe [Event]
$sel:events:OnExitLifecycle' :: OnExitLifecycle -> Maybe [Event]
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Event]
events

instance Prelude.NFData OnExitLifecycle where
  rnf :: OnExitLifecycle -> ()
rnf OnExitLifecycle' {Maybe [Event]
events :: Maybe [Event]
$sel:events:OnExitLifecycle' :: OnExitLifecycle -> Maybe [Event]
..} = forall a. NFData a => a -> ()
Prelude.rnf Maybe [Event]
events

instance Data.ToJSON OnExitLifecycle where
  toJSON :: OnExitLifecycle -> Value
toJSON OnExitLifecycle' {Maybe [Event]
events :: Maybe [Event]
$sel:events:OnExitLifecycle' :: OnExitLifecycle -> Maybe [Event]
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [(Key
"events" 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 [Event]
events]
      )