{-# 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.GameLift.Types.PlayerLatencyPolicy
-- 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.GameLift.Types.PlayerLatencyPolicy 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

-- | Sets a latency cap for individual players when placing a game session.
-- With a latency policy in force, a game session cannot be placed in a
-- fleet location where a player reports latency higher than the cap.
-- Latency policies are used only with placement request that provide
-- player latency information. Player latency policies can be stacked to
-- gradually relax latency requirements over time.
--
-- /See:/ 'newPlayerLatencyPolicy' smart constructor.
data PlayerLatencyPolicy = PlayerLatencyPolicy'
  { -- | The maximum latency value that is allowed for any player, in
    -- milliseconds. All policies must have a value set for this property.
    PlayerLatencyPolicy -> Maybe Natural
maximumIndividualPlayerLatencyMilliseconds :: Prelude.Maybe Prelude.Natural,
    -- | The length of time, in seconds, that the policy is enforced while
    -- placing a new game session. A null value for this property means that
    -- the policy is enforced until the queue times out.
    PlayerLatencyPolicy -> Maybe Natural
policyDurationSeconds :: Prelude.Maybe Prelude.Natural
  }
  deriving (PlayerLatencyPolicy -> PlayerLatencyPolicy -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PlayerLatencyPolicy -> PlayerLatencyPolicy -> Bool
$c/= :: PlayerLatencyPolicy -> PlayerLatencyPolicy -> Bool
== :: PlayerLatencyPolicy -> PlayerLatencyPolicy -> Bool
$c== :: PlayerLatencyPolicy -> PlayerLatencyPolicy -> Bool
Prelude.Eq, ReadPrec [PlayerLatencyPolicy]
ReadPrec PlayerLatencyPolicy
Int -> ReadS PlayerLatencyPolicy
ReadS [PlayerLatencyPolicy]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PlayerLatencyPolicy]
$creadListPrec :: ReadPrec [PlayerLatencyPolicy]
readPrec :: ReadPrec PlayerLatencyPolicy
$creadPrec :: ReadPrec PlayerLatencyPolicy
readList :: ReadS [PlayerLatencyPolicy]
$creadList :: ReadS [PlayerLatencyPolicy]
readsPrec :: Int -> ReadS PlayerLatencyPolicy
$creadsPrec :: Int -> ReadS PlayerLatencyPolicy
Prelude.Read, Int -> PlayerLatencyPolicy -> ShowS
[PlayerLatencyPolicy] -> ShowS
PlayerLatencyPolicy -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PlayerLatencyPolicy] -> ShowS
$cshowList :: [PlayerLatencyPolicy] -> ShowS
show :: PlayerLatencyPolicy -> String
$cshow :: PlayerLatencyPolicy -> String
showsPrec :: Int -> PlayerLatencyPolicy -> ShowS
$cshowsPrec :: Int -> PlayerLatencyPolicy -> ShowS
Prelude.Show, forall x. Rep PlayerLatencyPolicy x -> PlayerLatencyPolicy
forall x. PlayerLatencyPolicy -> Rep PlayerLatencyPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PlayerLatencyPolicy x -> PlayerLatencyPolicy
$cfrom :: forall x. PlayerLatencyPolicy -> Rep PlayerLatencyPolicy x
Prelude.Generic)

-- |
-- Create a value of 'PlayerLatencyPolicy' 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:
--
-- 'maximumIndividualPlayerLatencyMilliseconds', 'playerLatencyPolicy_maximumIndividualPlayerLatencyMilliseconds' - The maximum latency value that is allowed for any player, in
-- milliseconds. All policies must have a value set for this property.
--
-- 'policyDurationSeconds', 'playerLatencyPolicy_policyDurationSeconds' - The length of time, in seconds, that the policy is enforced while
-- placing a new game session. A null value for this property means that
-- the policy is enforced until the queue times out.
newPlayerLatencyPolicy ::
  PlayerLatencyPolicy
newPlayerLatencyPolicy :: PlayerLatencyPolicy
newPlayerLatencyPolicy =
  PlayerLatencyPolicy'
    { $sel:maximumIndividualPlayerLatencyMilliseconds:PlayerLatencyPolicy' :: Maybe Natural
maximumIndividualPlayerLatencyMilliseconds =
        forall a. Maybe a
Prelude.Nothing,
      $sel:policyDurationSeconds:PlayerLatencyPolicy' :: Maybe Natural
policyDurationSeconds = forall a. Maybe a
Prelude.Nothing
    }

-- | The maximum latency value that is allowed for any player, in
-- milliseconds. All policies must have a value set for this property.
playerLatencyPolicy_maximumIndividualPlayerLatencyMilliseconds :: Lens.Lens' PlayerLatencyPolicy (Prelude.Maybe Prelude.Natural)
playerLatencyPolicy_maximumIndividualPlayerLatencyMilliseconds :: Lens' PlayerLatencyPolicy (Maybe Natural)
playerLatencyPolicy_maximumIndividualPlayerLatencyMilliseconds = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PlayerLatencyPolicy' {Maybe Natural
maximumIndividualPlayerLatencyMilliseconds :: Maybe Natural
$sel:maximumIndividualPlayerLatencyMilliseconds:PlayerLatencyPolicy' :: PlayerLatencyPolicy -> Maybe Natural
maximumIndividualPlayerLatencyMilliseconds} -> Maybe Natural
maximumIndividualPlayerLatencyMilliseconds) (\s :: PlayerLatencyPolicy
s@PlayerLatencyPolicy' {} Maybe Natural
a -> PlayerLatencyPolicy
s {$sel:maximumIndividualPlayerLatencyMilliseconds:PlayerLatencyPolicy' :: Maybe Natural
maximumIndividualPlayerLatencyMilliseconds = Maybe Natural
a} :: PlayerLatencyPolicy)

-- | The length of time, in seconds, that the policy is enforced while
-- placing a new game session. A null value for this property means that
-- the policy is enforced until the queue times out.
playerLatencyPolicy_policyDurationSeconds :: Lens.Lens' PlayerLatencyPolicy (Prelude.Maybe Prelude.Natural)
playerLatencyPolicy_policyDurationSeconds :: Lens' PlayerLatencyPolicy (Maybe Natural)
playerLatencyPolicy_policyDurationSeconds = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PlayerLatencyPolicy' {Maybe Natural
policyDurationSeconds :: Maybe Natural
$sel:policyDurationSeconds:PlayerLatencyPolicy' :: PlayerLatencyPolicy -> Maybe Natural
policyDurationSeconds} -> Maybe Natural
policyDurationSeconds) (\s :: PlayerLatencyPolicy
s@PlayerLatencyPolicy' {} Maybe Natural
a -> PlayerLatencyPolicy
s {$sel:policyDurationSeconds:PlayerLatencyPolicy' :: Maybe Natural
policyDurationSeconds = Maybe Natural
a} :: PlayerLatencyPolicy)

instance Data.FromJSON PlayerLatencyPolicy where
  parseJSON :: Value -> Parser PlayerLatencyPolicy
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"PlayerLatencyPolicy"
      ( \Object
x ->
          Maybe Natural -> Maybe Natural -> PlayerLatencyPolicy
PlayerLatencyPolicy'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( Object
x
                            forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"MaximumIndividualPlayerLatencyMilliseconds"
                        )
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"PolicyDurationSeconds")
      )

instance Prelude.Hashable PlayerLatencyPolicy where
  hashWithSalt :: Int -> PlayerLatencyPolicy -> Int
hashWithSalt Int
_salt PlayerLatencyPolicy' {Maybe Natural
policyDurationSeconds :: Maybe Natural
maximumIndividualPlayerLatencyMilliseconds :: Maybe Natural
$sel:policyDurationSeconds:PlayerLatencyPolicy' :: PlayerLatencyPolicy -> Maybe Natural
$sel:maximumIndividualPlayerLatencyMilliseconds:PlayerLatencyPolicy' :: PlayerLatencyPolicy -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
maximumIndividualPlayerLatencyMilliseconds
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
policyDurationSeconds

instance Prelude.NFData PlayerLatencyPolicy where
  rnf :: PlayerLatencyPolicy -> ()
rnf PlayerLatencyPolicy' {Maybe Natural
policyDurationSeconds :: Maybe Natural
maximumIndividualPlayerLatencyMilliseconds :: Maybe Natural
$sel:policyDurationSeconds:PlayerLatencyPolicy' :: PlayerLatencyPolicy -> Maybe Natural
$sel:maximumIndividualPlayerLatencyMilliseconds:PlayerLatencyPolicy' :: PlayerLatencyPolicy -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf
      Maybe Natural
maximumIndividualPlayerLatencyMilliseconds
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
policyDurationSeconds

instance Data.ToJSON PlayerLatencyPolicy where
  toJSON :: PlayerLatencyPolicy -> Value
toJSON PlayerLatencyPolicy' {Maybe Natural
policyDurationSeconds :: Maybe Natural
maximumIndividualPlayerLatencyMilliseconds :: Maybe Natural
$sel:policyDurationSeconds:PlayerLatencyPolicy' :: PlayerLatencyPolicy -> Maybe Natural
$sel:maximumIndividualPlayerLatencyMilliseconds:PlayerLatencyPolicy' :: PlayerLatencyPolicy -> Maybe Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ ( Key
"MaximumIndividualPlayerLatencyMilliseconds"
                forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=
            )
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
maximumIndividualPlayerLatencyMilliseconds,
            (Key
"PolicyDurationSeconds" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
policyDurationSeconds
          ]
      )