{-# 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.ELB.Types.ConnectionDraining
-- 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.ELB.Types.ConnectionDraining where

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

-- | Information about the @ConnectionDraining@ attribute.
--
-- /See:/ 'newConnectionDraining' smart constructor.
data ConnectionDraining = ConnectionDraining'
  { -- | The maximum time, in seconds, to keep the existing connections open
    -- before deregistering the instances.
    ConnectionDraining -> Maybe Int
timeout :: Prelude.Maybe Prelude.Int,
    -- | Specifies whether connection draining is enabled for the load balancer.
    ConnectionDraining -> Bool
enabled :: Prelude.Bool
  }
  deriving (ConnectionDraining -> ConnectionDraining -> Bool
(ConnectionDraining -> ConnectionDraining -> Bool)
-> (ConnectionDraining -> ConnectionDraining -> Bool)
-> Eq ConnectionDraining
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ConnectionDraining -> ConnectionDraining -> Bool
$c/= :: ConnectionDraining -> ConnectionDraining -> Bool
== :: ConnectionDraining -> ConnectionDraining -> Bool
$c== :: ConnectionDraining -> ConnectionDraining -> Bool
Prelude.Eq, ReadPrec [ConnectionDraining]
ReadPrec ConnectionDraining
Int -> ReadS ConnectionDraining
ReadS [ConnectionDraining]
(Int -> ReadS ConnectionDraining)
-> ReadS [ConnectionDraining]
-> ReadPrec ConnectionDraining
-> ReadPrec [ConnectionDraining]
-> Read ConnectionDraining
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ConnectionDraining]
$creadListPrec :: ReadPrec [ConnectionDraining]
readPrec :: ReadPrec ConnectionDraining
$creadPrec :: ReadPrec ConnectionDraining
readList :: ReadS [ConnectionDraining]
$creadList :: ReadS [ConnectionDraining]
readsPrec :: Int -> ReadS ConnectionDraining
$creadsPrec :: Int -> ReadS ConnectionDraining
Prelude.Read, Int -> ConnectionDraining -> ShowS
[ConnectionDraining] -> ShowS
ConnectionDraining -> String
(Int -> ConnectionDraining -> ShowS)
-> (ConnectionDraining -> String)
-> ([ConnectionDraining] -> ShowS)
-> Show ConnectionDraining
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ConnectionDraining] -> ShowS
$cshowList :: [ConnectionDraining] -> ShowS
show :: ConnectionDraining -> String
$cshow :: ConnectionDraining -> String
showsPrec :: Int -> ConnectionDraining -> ShowS
$cshowsPrec :: Int -> ConnectionDraining -> ShowS
Prelude.Show, (forall x. ConnectionDraining -> Rep ConnectionDraining x)
-> (forall x. Rep ConnectionDraining x -> ConnectionDraining)
-> Generic ConnectionDraining
forall x. Rep ConnectionDraining x -> ConnectionDraining
forall x. ConnectionDraining -> Rep ConnectionDraining x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ConnectionDraining x -> ConnectionDraining
$cfrom :: forall x. ConnectionDraining -> Rep ConnectionDraining x
Prelude.Generic)

-- |
-- Create a value of 'ConnectionDraining' 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:
--
-- 'timeout', 'connectionDraining_timeout' - The maximum time, in seconds, to keep the existing connections open
-- before deregistering the instances.
--
-- 'enabled', 'connectionDraining_enabled' - Specifies whether connection draining is enabled for the load balancer.
newConnectionDraining ::
  -- | 'enabled'
  Prelude.Bool ->
  ConnectionDraining
newConnectionDraining :: Bool -> ConnectionDraining
newConnectionDraining Bool
pEnabled_ =
  ConnectionDraining' :: Maybe Int -> Bool -> ConnectionDraining
ConnectionDraining'
    { $sel:timeout:ConnectionDraining' :: Maybe Int
timeout = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:enabled:ConnectionDraining' :: Bool
enabled = Bool
pEnabled_
    }

-- | The maximum time, in seconds, to keep the existing connections open
-- before deregistering the instances.
connectionDraining_timeout :: Lens.Lens' ConnectionDraining (Prelude.Maybe Prelude.Int)
connectionDraining_timeout :: (Maybe Int -> f (Maybe Int))
-> ConnectionDraining -> f ConnectionDraining
connectionDraining_timeout = (ConnectionDraining -> Maybe Int)
-> (ConnectionDraining -> Maybe Int -> ConnectionDraining)
-> Lens
     ConnectionDraining ConnectionDraining (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ConnectionDraining' {Maybe Int
timeout :: Maybe Int
$sel:timeout:ConnectionDraining' :: ConnectionDraining -> Maybe Int
timeout} -> Maybe Int
timeout) (\s :: ConnectionDraining
s@ConnectionDraining' {} Maybe Int
a -> ConnectionDraining
s {$sel:timeout:ConnectionDraining' :: Maybe Int
timeout = Maybe Int
a} :: ConnectionDraining)

-- | Specifies whether connection draining is enabled for the load balancer.
connectionDraining_enabled :: Lens.Lens' ConnectionDraining Prelude.Bool
connectionDraining_enabled :: (Bool -> f Bool) -> ConnectionDraining -> f ConnectionDraining
connectionDraining_enabled = (ConnectionDraining -> Bool)
-> (ConnectionDraining -> Bool -> ConnectionDraining)
-> Lens ConnectionDraining ConnectionDraining Bool Bool
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ConnectionDraining' {Bool
enabled :: Bool
$sel:enabled:ConnectionDraining' :: ConnectionDraining -> Bool
enabled} -> Bool
enabled) (\s :: ConnectionDraining
s@ConnectionDraining' {} Bool
a -> ConnectionDraining
s {$sel:enabled:ConnectionDraining' :: Bool
enabled = Bool
a} :: ConnectionDraining)

instance Core.FromXML ConnectionDraining where
  parseXML :: [Node] -> Either String ConnectionDraining
parseXML [Node]
x =
    Maybe Int -> Bool -> ConnectionDraining
ConnectionDraining'
      (Maybe Int -> Bool -> ConnectionDraining)
-> Either String (Maybe Int)
-> Either String (Bool -> ConnectionDraining)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Int)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Timeout")
      Either String (Bool -> ConnectionDraining)
-> Either String Bool -> Either String ConnectionDraining
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Bool
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Enabled")

instance Prelude.Hashable ConnectionDraining

instance Prelude.NFData ConnectionDraining

instance Core.ToQuery ConnectionDraining where
  toQuery :: ConnectionDraining -> QueryString
toQuery ConnectionDraining' {Bool
Maybe Int
enabled :: Bool
timeout :: Maybe Int
$sel:enabled:ConnectionDraining' :: ConnectionDraining -> Bool
$sel:timeout:ConnectionDraining' :: ConnectionDraining -> Maybe Int
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Timeout" ByteString -> Maybe Int -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Int
timeout,
        ByteString
"Enabled" ByteString -> Bool -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Bool
enabled
      ]