{-# 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.CloudFront.Types.SessionStickinessConfig
-- 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.CloudFront.Types.SessionStickinessConfig where

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

-- | Session stickiness provides the ability to define multiple requests from
-- a single viewer as a single session. This prevents the potentially
-- inconsistent experience of sending some of a given user\'s requests to
-- your staging distribution, while others are sent to your primary
-- distribution. Define the session duration using TTL values.
--
-- /See:/ 'newSessionStickinessConfig' smart constructor.
data SessionStickinessConfig = SessionStickinessConfig'
  { -- | The amount of time after which you want sessions to cease if no requests
    -- are received. Allowed values are 300–3600 seconds (5–60 minutes).
    --
    -- The value must be less than or equal to @MaximumTTL@.
    SessionStickinessConfig -> Int
idleTTL :: Prelude.Int,
    -- | The maximum amount of time to consider requests from the viewer as being
    -- part of the same session. Allowed values are 300–3600 seconds (5–60
    -- minutes).
    --
    -- The value must be less than or equal to @IdleTTL@.
    SessionStickinessConfig -> Int
maximumTTL :: Prelude.Int
  }
  deriving (SessionStickinessConfig -> SessionStickinessConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SessionStickinessConfig -> SessionStickinessConfig -> Bool
$c/= :: SessionStickinessConfig -> SessionStickinessConfig -> Bool
== :: SessionStickinessConfig -> SessionStickinessConfig -> Bool
$c== :: SessionStickinessConfig -> SessionStickinessConfig -> Bool
Prelude.Eq, ReadPrec [SessionStickinessConfig]
ReadPrec SessionStickinessConfig
Int -> ReadS SessionStickinessConfig
ReadS [SessionStickinessConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SessionStickinessConfig]
$creadListPrec :: ReadPrec [SessionStickinessConfig]
readPrec :: ReadPrec SessionStickinessConfig
$creadPrec :: ReadPrec SessionStickinessConfig
readList :: ReadS [SessionStickinessConfig]
$creadList :: ReadS [SessionStickinessConfig]
readsPrec :: Int -> ReadS SessionStickinessConfig
$creadsPrec :: Int -> ReadS SessionStickinessConfig
Prelude.Read, Int -> SessionStickinessConfig -> ShowS
[SessionStickinessConfig] -> ShowS
SessionStickinessConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SessionStickinessConfig] -> ShowS
$cshowList :: [SessionStickinessConfig] -> ShowS
show :: SessionStickinessConfig -> String
$cshow :: SessionStickinessConfig -> String
showsPrec :: Int -> SessionStickinessConfig -> ShowS
$cshowsPrec :: Int -> SessionStickinessConfig -> ShowS
Prelude.Show, forall x. Rep SessionStickinessConfig x -> SessionStickinessConfig
forall x. SessionStickinessConfig -> Rep SessionStickinessConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SessionStickinessConfig x -> SessionStickinessConfig
$cfrom :: forall x. SessionStickinessConfig -> Rep SessionStickinessConfig x
Prelude.Generic)

-- |
-- Create a value of 'SessionStickinessConfig' 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:
--
-- 'idleTTL', 'sessionStickinessConfig_idleTTL' - The amount of time after which you want sessions to cease if no requests
-- are received. Allowed values are 300–3600 seconds (5–60 minutes).
--
-- The value must be less than or equal to @MaximumTTL@.
--
-- 'maximumTTL', 'sessionStickinessConfig_maximumTTL' - The maximum amount of time to consider requests from the viewer as being
-- part of the same session. Allowed values are 300–3600 seconds (5–60
-- minutes).
--
-- The value must be less than or equal to @IdleTTL@.
newSessionStickinessConfig ::
  -- | 'idleTTL'
  Prelude.Int ->
  -- | 'maximumTTL'
  Prelude.Int ->
  SessionStickinessConfig
newSessionStickinessConfig :: Int -> Int -> SessionStickinessConfig
newSessionStickinessConfig Int
pIdleTTL_ Int
pMaximumTTL_ =
  SessionStickinessConfig'
    { $sel:idleTTL:SessionStickinessConfig' :: Int
idleTTL = Int
pIdleTTL_,
      $sel:maximumTTL:SessionStickinessConfig' :: Int
maximumTTL = Int
pMaximumTTL_
    }

-- | The amount of time after which you want sessions to cease if no requests
-- are received. Allowed values are 300–3600 seconds (5–60 minutes).
--
-- The value must be less than or equal to @MaximumTTL@.
sessionStickinessConfig_idleTTL :: Lens.Lens' SessionStickinessConfig Prelude.Int
sessionStickinessConfig_idleTTL :: Lens' SessionStickinessConfig Int
sessionStickinessConfig_idleTTL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SessionStickinessConfig' {Int
idleTTL :: Int
$sel:idleTTL:SessionStickinessConfig' :: SessionStickinessConfig -> Int
idleTTL} -> Int
idleTTL) (\s :: SessionStickinessConfig
s@SessionStickinessConfig' {} Int
a -> SessionStickinessConfig
s {$sel:idleTTL:SessionStickinessConfig' :: Int
idleTTL = Int
a} :: SessionStickinessConfig)

-- | The maximum amount of time to consider requests from the viewer as being
-- part of the same session. Allowed values are 300–3600 seconds (5–60
-- minutes).
--
-- The value must be less than or equal to @IdleTTL@.
sessionStickinessConfig_maximumTTL :: Lens.Lens' SessionStickinessConfig Prelude.Int
sessionStickinessConfig_maximumTTL :: Lens' SessionStickinessConfig Int
sessionStickinessConfig_maximumTTL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SessionStickinessConfig' {Int
maximumTTL :: Int
$sel:maximumTTL:SessionStickinessConfig' :: SessionStickinessConfig -> Int
maximumTTL} -> Int
maximumTTL) (\s :: SessionStickinessConfig
s@SessionStickinessConfig' {} Int
a -> SessionStickinessConfig
s {$sel:maximumTTL:SessionStickinessConfig' :: Int
maximumTTL = Int
a} :: SessionStickinessConfig)

instance Data.FromXML SessionStickinessConfig where
  parseXML :: [Node] -> Either String SessionStickinessConfig
parseXML [Node]
x =
    Int -> Int -> SessionStickinessConfig
SessionStickinessConfig'
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"IdleTTL")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"MaximumTTL")

instance Prelude.Hashable SessionStickinessConfig where
  hashWithSalt :: Int -> SessionStickinessConfig -> Int
hashWithSalt Int
_salt SessionStickinessConfig' {Int
maximumTTL :: Int
idleTTL :: Int
$sel:maximumTTL:SessionStickinessConfig' :: SessionStickinessConfig -> Int
$sel:idleTTL:SessionStickinessConfig' :: SessionStickinessConfig -> Int
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Int
idleTTL
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Int
maximumTTL

instance Prelude.NFData SessionStickinessConfig where
  rnf :: SessionStickinessConfig -> ()
rnf SessionStickinessConfig' {Int
maximumTTL :: Int
idleTTL :: Int
$sel:maximumTTL:SessionStickinessConfig' :: SessionStickinessConfig -> Int
$sel:idleTTL:SessionStickinessConfig' :: SessionStickinessConfig -> Int
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Int
idleTTL
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
maximumTTL

instance Data.ToXML SessionStickinessConfig where
  toXML :: SessionStickinessConfig -> XML
toXML SessionStickinessConfig' {Int
maximumTTL :: Int
idleTTL :: Int
$sel:maximumTTL:SessionStickinessConfig' :: SessionStickinessConfig -> Int
$sel:idleTTL:SessionStickinessConfig' :: SessionStickinessConfig -> Int
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"IdleTTL" forall a. ToXML a => Name -> a -> XML
Data.@= Int
idleTTL,
        Name
"MaximumTTL" forall a. ToXML a => Name -> a -> XML
Data.@= Int
maximumTTL
      ]