{-# 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.OpsWorks.Types.ShutdownEventConfiguration
-- 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.OpsWorks.Types.ShutdownEventConfiguration where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | The Shutdown event configuration.
--
-- /See:/ 'newShutdownEventConfiguration' smart constructor.
data ShutdownEventConfiguration = ShutdownEventConfiguration'
  { -- | The time, in seconds, that AWS OpsWorks Stacks will wait after
    -- triggering a Shutdown event before shutting down an instance.
    ShutdownEventConfiguration -> Maybe Int
executionTimeout :: Prelude.Maybe Prelude.Int,
    -- | Whether to enable Elastic Load Balancing connection draining. For more
    -- information, see
    -- <https://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/TerminologyandKeyConcepts.html#conn-drain Connection Draining>
    ShutdownEventConfiguration -> Maybe Bool
delayUntilElbConnectionsDrained :: Prelude.Maybe Prelude.Bool
  }
  deriving (ShutdownEventConfiguration -> ShutdownEventConfiguration -> Bool
(ShutdownEventConfiguration -> ShutdownEventConfiguration -> Bool)
-> (ShutdownEventConfiguration
    -> ShutdownEventConfiguration -> Bool)
-> Eq ShutdownEventConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ShutdownEventConfiguration -> ShutdownEventConfiguration -> Bool
$c/= :: ShutdownEventConfiguration -> ShutdownEventConfiguration -> Bool
== :: ShutdownEventConfiguration -> ShutdownEventConfiguration -> Bool
$c== :: ShutdownEventConfiguration -> ShutdownEventConfiguration -> Bool
Prelude.Eq, ReadPrec [ShutdownEventConfiguration]
ReadPrec ShutdownEventConfiguration
Int -> ReadS ShutdownEventConfiguration
ReadS [ShutdownEventConfiguration]
(Int -> ReadS ShutdownEventConfiguration)
-> ReadS [ShutdownEventConfiguration]
-> ReadPrec ShutdownEventConfiguration
-> ReadPrec [ShutdownEventConfiguration]
-> Read ShutdownEventConfiguration
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ShutdownEventConfiguration]
$creadListPrec :: ReadPrec [ShutdownEventConfiguration]
readPrec :: ReadPrec ShutdownEventConfiguration
$creadPrec :: ReadPrec ShutdownEventConfiguration
readList :: ReadS [ShutdownEventConfiguration]
$creadList :: ReadS [ShutdownEventConfiguration]
readsPrec :: Int -> ReadS ShutdownEventConfiguration
$creadsPrec :: Int -> ReadS ShutdownEventConfiguration
Prelude.Read, Int -> ShutdownEventConfiguration -> ShowS
[ShutdownEventConfiguration] -> ShowS
ShutdownEventConfiguration -> String
(Int -> ShutdownEventConfiguration -> ShowS)
-> (ShutdownEventConfiguration -> String)
-> ([ShutdownEventConfiguration] -> ShowS)
-> Show ShutdownEventConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ShutdownEventConfiguration] -> ShowS
$cshowList :: [ShutdownEventConfiguration] -> ShowS
show :: ShutdownEventConfiguration -> String
$cshow :: ShutdownEventConfiguration -> String
showsPrec :: Int -> ShutdownEventConfiguration -> ShowS
$cshowsPrec :: Int -> ShutdownEventConfiguration -> ShowS
Prelude.Show, (forall x.
 ShutdownEventConfiguration -> Rep ShutdownEventConfiguration x)
-> (forall x.
    Rep ShutdownEventConfiguration x -> ShutdownEventConfiguration)
-> Generic ShutdownEventConfiguration
forall x.
Rep ShutdownEventConfiguration x -> ShutdownEventConfiguration
forall x.
ShutdownEventConfiguration -> Rep ShutdownEventConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ShutdownEventConfiguration x -> ShutdownEventConfiguration
$cfrom :: forall x.
ShutdownEventConfiguration -> Rep ShutdownEventConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'ShutdownEventConfiguration' 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:
--
-- 'executionTimeout', 'shutdownEventConfiguration_executionTimeout' - The time, in seconds, that AWS OpsWorks Stacks will wait after
-- triggering a Shutdown event before shutting down an instance.
--
-- 'delayUntilElbConnectionsDrained', 'shutdownEventConfiguration_delayUntilElbConnectionsDrained' - Whether to enable Elastic Load Balancing connection draining. For more
-- information, see
-- <https://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/TerminologyandKeyConcepts.html#conn-drain Connection Draining>
newShutdownEventConfiguration ::
  ShutdownEventConfiguration
newShutdownEventConfiguration :: ShutdownEventConfiguration
newShutdownEventConfiguration =
  ShutdownEventConfiguration' :: Maybe Int -> Maybe Bool -> ShutdownEventConfiguration
ShutdownEventConfiguration'
    { $sel:executionTimeout:ShutdownEventConfiguration' :: Maybe Int
executionTimeout =
        Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:delayUntilElbConnectionsDrained:ShutdownEventConfiguration' :: Maybe Bool
delayUntilElbConnectionsDrained =
        Maybe Bool
forall a. Maybe a
Prelude.Nothing
    }

-- | The time, in seconds, that AWS OpsWorks Stacks will wait after
-- triggering a Shutdown event before shutting down an instance.
shutdownEventConfiguration_executionTimeout :: Lens.Lens' ShutdownEventConfiguration (Prelude.Maybe Prelude.Int)
shutdownEventConfiguration_executionTimeout :: (Maybe Int -> f (Maybe Int))
-> ShutdownEventConfiguration -> f ShutdownEventConfiguration
shutdownEventConfiguration_executionTimeout = (ShutdownEventConfiguration -> Maybe Int)
-> (ShutdownEventConfiguration
    -> Maybe Int -> ShutdownEventConfiguration)
-> Lens
     ShutdownEventConfiguration
     ShutdownEventConfiguration
     (Maybe Int)
     (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ShutdownEventConfiguration' {Maybe Int
executionTimeout :: Maybe Int
$sel:executionTimeout:ShutdownEventConfiguration' :: ShutdownEventConfiguration -> Maybe Int
executionTimeout} -> Maybe Int
executionTimeout) (\s :: ShutdownEventConfiguration
s@ShutdownEventConfiguration' {} Maybe Int
a -> ShutdownEventConfiguration
s {$sel:executionTimeout:ShutdownEventConfiguration' :: Maybe Int
executionTimeout = Maybe Int
a} :: ShutdownEventConfiguration)

-- | Whether to enable Elastic Load Balancing connection draining. For more
-- information, see
-- <https://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/TerminologyandKeyConcepts.html#conn-drain Connection Draining>
shutdownEventConfiguration_delayUntilElbConnectionsDrained :: Lens.Lens' ShutdownEventConfiguration (Prelude.Maybe Prelude.Bool)
shutdownEventConfiguration_delayUntilElbConnectionsDrained :: (Maybe Bool -> f (Maybe Bool))
-> ShutdownEventConfiguration -> f ShutdownEventConfiguration
shutdownEventConfiguration_delayUntilElbConnectionsDrained = (ShutdownEventConfiguration -> Maybe Bool)
-> (ShutdownEventConfiguration
    -> Maybe Bool -> ShutdownEventConfiguration)
-> Lens
     ShutdownEventConfiguration
     ShutdownEventConfiguration
     (Maybe Bool)
     (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ShutdownEventConfiguration' {Maybe Bool
delayUntilElbConnectionsDrained :: Maybe Bool
$sel:delayUntilElbConnectionsDrained:ShutdownEventConfiguration' :: ShutdownEventConfiguration -> Maybe Bool
delayUntilElbConnectionsDrained} -> Maybe Bool
delayUntilElbConnectionsDrained) (\s :: ShutdownEventConfiguration
s@ShutdownEventConfiguration' {} Maybe Bool
a -> ShutdownEventConfiguration
s {$sel:delayUntilElbConnectionsDrained:ShutdownEventConfiguration' :: Maybe Bool
delayUntilElbConnectionsDrained = Maybe Bool
a} :: ShutdownEventConfiguration)

instance Core.FromJSON ShutdownEventConfiguration where
  parseJSON :: Value -> Parser ShutdownEventConfiguration
parseJSON =
    String
-> (Object -> Parser ShutdownEventConfiguration)
-> Value
-> Parser ShutdownEventConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ShutdownEventConfiguration"
      ( \Object
x ->
          Maybe Int -> Maybe Bool -> ShutdownEventConfiguration
ShutdownEventConfiguration'
            (Maybe Int -> Maybe Bool -> ShutdownEventConfiguration)
-> Parser (Maybe Int)
-> Parser (Maybe Bool -> ShutdownEventConfiguration)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ExecutionTimeout")
            Parser (Maybe Bool -> ShutdownEventConfiguration)
-> Parser (Maybe Bool) -> Parser ShutdownEventConfiguration
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"DelayUntilElbConnectionsDrained")
      )

instance Prelude.Hashable ShutdownEventConfiguration

instance Prelude.NFData ShutdownEventConfiguration

instance Core.ToJSON ShutdownEventConfiguration where
  toJSON :: ShutdownEventConfiguration -> Value
toJSON ShutdownEventConfiguration' {Maybe Bool
Maybe Int
delayUntilElbConnectionsDrained :: Maybe Bool
executionTimeout :: Maybe Int
$sel:delayUntilElbConnectionsDrained:ShutdownEventConfiguration' :: ShutdownEventConfiguration -> Maybe Bool
$sel:executionTimeout:ShutdownEventConfiguration' :: ShutdownEventConfiguration -> Maybe Int
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"ExecutionTimeout" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Int -> Pair) -> Maybe Int -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Int
executionTimeout,
            (Text
"DelayUntilElbConnectionsDrained" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
delayUntilElbConnectionsDrained
          ]
      )