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

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

-- | Specifies the actions that are performed when the state is entered and
-- the @condition@ is @TRUE@.
onEnterLifecycle_events :: Lens.Lens' OnEnterLifecycle (Prelude.Maybe [Event])
onEnterLifecycle_events :: (Maybe [Event] -> f (Maybe [Event]))
-> OnEnterLifecycle -> f OnEnterLifecycle
onEnterLifecycle_events = (OnEnterLifecycle -> Maybe [Event])
-> (OnEnterLifecycle -> Maybe [Event] -> OnEnterLifecycle)
-> Lens
     OnEnterLifecycle OnEnterLifecycle (Maybe [Event]) (Maybe [Event])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OnEnterLifecycle' {Maybe [Event]
events :: Maybe [Event]
$sel:events:OnEnterLifecycle' :: OnEnterLifecycle -> Maybe [Event]
events} -> Maybe [Event]
events) (\s :: OnEnterLifecycle
s@OnEnterLifecycle' {} Maybe [Event]
a -> OnEnterLifecycle
s {$sel:events:OnEnterLifecycle' :: Maybe [Event]
events = Maybe [Event]
a} :: OnEnterLifecycle) ((Maybe [Event] -> f (Maybe [Event]))
 -> OnEnterLifecycle -> f OnEnterLifecycle)
-> ((Maybe [Event] -> f (Maybe [Event]))
    -> Maybe [Event] -> f (Maybe [Event]))
-> (Maybe [Event] -> f (Maybe [Event]))
-> OnEnterLifecycle
-> f OnEnterLifecycle
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 OnEnterLifecycle where
  parseJSON :: Value -> Parser OnEnterLifecycle
parseJSON =
    String
-> (Object -> Parser OnEnterLifecycle)
-> Value
-> Parser OnEnterLifecycle
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"OnEnterLifecycle"
      ( \Object
x ->
          Maybe [Event] -> OnEnterLifecycle
OnEnterLifecycle'
            (Maybe [Event] -> OnEnterLifecycle)
-> Parser (Maybe [Event]) -> Parser OnEnterLifecycle
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 OnEnterLifecycle

instance Prelude.NFData OnEnterLifecycle

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