{-# 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.ELBV2.Types.TargetGroupStickinessConfig
-- 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.ELBV2.Types.TargetGroupStickinessConfig where

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

-- | Information about the target group stickiness for a rule.
--
-- /See:/ 'newTargetGroupStickinessConfig' smart constructor.
data TargetGroupStickinessConfig = TargetGroupStickinessConfig'
  { -- | Indicates whether target group stickiness is enabled.
    TargetGroupStickinessConfig -> Maybe Bool
enabled :: Prelude.Maybe Prelude.Bool,
    -- | The time period, in seconds, during which requests from a client should
    -- be routed to the same target group. The range is 1-604800 seconds (7
    -- days).
    TargetGroupStickinessConfig -> Maybe Int
durationSeconds :: Prelude.Maybe Prelude.Int
  }
  deriving (TargetGroupStickinessConfig -> TargetGroupStickinessConfig -> Bool
(TargetGroupStickinessConfig
 -> TargetGroupStickinessConfig -> Bool)
-> (TargetGroupStickinessConfig
    -> TargetGroupStickinessConfig -> Bool)
-> Eq TargetGroupStickinessConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TargetGroupStickinessConfig -> TargetGroupStickinessConfig -> Bool
$c/= :: TargetGroupStickinessConfig -> TargetGroupStickinessConfig -> Bool
== :: TargetGroupStickinessConfig -> TargetGroupStickinessConfig -> Bool
$c== :: TargetGroupStickinessConfig -> TargetGroupStickinessConfig -> Bool
Prelude.Eq, ReadPrec [TargetGroupStickinessConfig]
ReadPrec TargetGroupStickinessConfig
Int -> ReadS TargetGroupStickinessConfig
ReadS [TargetGroupStickinessConfig]
(Int -> ReadS TargetGroupStickinessConfig)
-> ReadS [TargetGroupStickinessConfig]
-> ReadPrec TargetGroupStickinessConfig
-> ReadPrec [TargetGroupStickinessConfig]
-> Read TargetGroupStickinessConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TargetGroupStickinessConfig]
$creadListPrec :: ReadPrec [TargetGroupStickinessConfig]
readPrec :: ReadPrec TargetGroupStickinessConfig
$creadPrec :: ReadPrec TargetGroupStickinessConfig
readList :: ReadS [TargetGroupStickinessConfig]
$creadList :: ReadS [TargetGroupStickinessConfig]
readsPrec :: Int -> ReadS TargetGroupStickinessConfig
$creadsPrec :: Int -> ReadS TargetGroupStickinessConfig
Prelude.Read, Int -> TargetGroupStickinessConfig -> ShowS
[TargetGroupStickinessConfig] -> ShowS
TargetGroupStickinessConfig -> String
(Int -> TargetGroupStickinessConfig -> ShowS)
-> (TargetGroupStickinessConfig -> String)
-> ([TargetGroupStickinessConfig] -> ShowS)
-> Show TargetGroupStickinessConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TargetGroupStickinessConfig] -> ShowS
$cshowList :: [TargetGroupStickinessConfig] -> ShowS
show :: TargetGroupStickinessConfig -> String
$cshow :: TargetGroupStickinessConfig -> String
showsPrec :: Int -> TargetGroupStickinessConfig -> ShowS
$cshowsPrec :: Int -> TargetGroupStickinessConfig -> ShowS
Prelude.Show, (forall x.
 TargetGroupStickinessConfig -> Rep TargetGroupStickinessConfig x)
-> (forall x.
    Rep TargetGroupStickinessConfig x -> TargetGroupStickinessConfig)
-> Generic TargetGroupStickinessConfig
forall x.
Rep TargetGroupStickinessConfig x -> TargetGroupStickinessConfig
forall x.
TargetGroupStickinessConfig -> Rep TargetGroupStickinessConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep TargetGroupStickinessConfig x -> TargetGroupStickinessConfig
$cfrom :: forall x.
TargetGroupStickinessConfig -> Rep TargetGroupStickinessConfig x
Prelude.Generic)

-- |
-- Create a value of 'TargetGroupStickinessConfig' 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:
--
-- 'enabled', 'targetGroupStickinessConfig_enabled' - Indicates whether target group stickiness is enabled.
--
-- 'durationSeconds', 'targetGroupStickinessConfig_durationSeconds' - The time period, in seconds, during which requests from a client should
-- be routed to the same target group. The range is 1-604800 seconds (7
-- days).
newTargetGroupStickinessConfig ::
  TargetGroupStickinessConfig
newTargetGroupStickinessConfig :: TargetGroupStickinessConfig
newTargetGroupStickinessConfig =
  TargetGroupStickinessConfig' :: Maybe Bool -> Maybe Int -> TargetGroupStickinessConfig
TargetGroupStickinessConfig'
    { $sel:enabled:TargetGroupStickinessConfig' :: Maybe Bool
enabled =
        Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:durationSeconds:TargetGroupStickinessConfig' :: Maybe Int
durationSeconds = Maybe Int
forall a. Maybe a
Prelude.Nothing
    }

-- | Indicates whether target group stickiness is enabled.
targetGroupStickinessConfig_enabled :: Lens.Lens' TargetGroupStickinessConfig (Prelude.Maybe Prelude.Bool)
targetGroupStickinessConfig_enabled :: (Maybe Bool -> f (Maybe Bool))
-> TargetGroupStickinessConfig -> f TargetGroupStickinessConfig
targetGroupStickinessConfig_enabled = (TargetGroupStickinessConfig -> Maybe Bool)
-> (TargetGroupStickinessConfig
    -> Maybe Bool -> TargetGroupStickinessConfig)
-> Lens
     TargetGroupStickinessConfig
     TargetGroupStickinessConfig
     (Maybe Bool)
     (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TargetGroupStickinessConfig' {Maybe Bool
enabled :: Maybe Bool
$sel:enabled:TargetGroupStickinessConfig' :: TargetGroupStickinessConfig -> Maybe Bool
enabled} -> Maybe Bool
enabled) (\s :: TargetGroupStickinessConfig
s@TargetGroupStickinessConfig' {} Maybe Bool
a -> TargetGroupStickinessConfig
s {$sel:enabled:TargetGroupStickinessConfig' :: Maybe Bool
enabled = Maybe Bool
a} :: TargetGroupStickinessConfig)

-- | The time period, in seconds, during which requests from a client should
-- be routed to the same target group. The range is 1-604800 seconds (7
-- days).
targetGroupStickinessConfig_durationSeconds :: Lens.Lens' TargetGroupStickinessConfig (Prelude.Maybe Prelude.Int)
targetGroupStickinessConfig_durationSeconds :: (Maybe Int -> f (Maybe Int))
-> TargetGroupStickinessConfig -> f TargetGroupStickinessConfig
targetGroupStickinessConfig_durationSeconds = (TargetGroupStickinessConfig -> Maybe Int)
-> (TargetGroupStickinessConfig
    -> Maybe Int -> TargetGroupStickinessConfig)
-> Lens
     TargetGroupStickinessConfig
     TargetGroupStickinessConfig
     (Maybe Int)
     (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TargetGroupStickinessConfig' {Maybe Int
durationSeconds :: Maybe Int
$sel:durationSeconds:TargetGroupStickinessConfig' :: TargetGroupStickinessConfig -> Maybe Int
durationSeconds} -> Maybe Int
durationSeconds) (\s :: TargetGroupStickinessConfig
s@TargetGroupStickinessConfig' {} Maybe Int
a -> TargetGroupStickinessConfig
s {$sel:durationSeconds:TargetGroupStickinessConfig' :: Maybe Int
durationSeconds = Maybe Int
a} :: TargetGroupStickinessConfig)

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

instance Prelude.Hashable TargetGroupStickinessConfig

instance Prelude.NFData TargetGroupStickinessConfig

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