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

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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.
--
-- Latency policies are part of a GameSessionQueue.
--
-- /See:/ 'newPlayerLatencyPolicy' smart constructor.
data PlayerLatencyPolicy = 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 -> Maybe Natural
policyDurationSeconds :: Prelude.Maybe Prelude.Natural,
    -- | 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
  }
  deriving (PlayerLatencyPolicy -> PlayerLatencyPolicy -> Bool
(PlayerLatencyPolicy -> PlayerLatencyPolicy -> Bool)
-> (PlayerLatencyPolicy -> PlayerLatencyPolicy -> Bool)
-> Eq PlayerLatencyPolicy
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]
(Int -> ReadS PlayerLatencyPolicy)
-> ReadS [PlayerLatencyPolicy]
-> ReadPrec PlayerLatencyPolicy
-> ReadPrec [PlayerLatencyPolicy]
-> Read 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
(Int -> PlayerLatencyPolicy -> ShowS)
-> (PlayerLatencyPolicy -> String)
-> ([PlayerLatencyPolicy] -> ShowS)
-> Show PlayerLatencyPolicy
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. PlayerLatencyPolicy -> Rep PlayerLatencyPolicy x)
-> (forall x. Rep PlayerLatencyPolicy x -> PlayerLatencyPolicy)
-> Generic PlayerLatencyPolicy
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:
--
-- '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.
--
-- '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.
newPlayerLatencyPolicy ::
  PlayerLatencyPolicy
newPlayerLatencyPolicy :: PlayerLatencyPolicy
newPlayerLatencyPolicy =
  PlayerLatencyPolicy' :: Maybe Natural -> Maybe Natural -> PlayerLatencyPolicy
PlayerLatencyPolicy'
    { $sel:policyDurationSeconds:PlayerLatencyPolicy' :: Maybe Natural
policyDurationSeconds =
        Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:maximumIndividualPlayerLatencyMilliseconds:PlayerLatencyPolicy' :: Maybe Natural
maximumIndividualPlayerLatencyMilliseconds =
        Maybe Natural
forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: (Maybe Natural -> f (Maybe Natural))
-> PlayerLatencyPolicy -> f PlayerLatencyPolicy
playerLatencyPolicy_policyDurationSeconds = (PlayerLatencyPolicy -> Maybe Natural)
-> (PlayerLatencyPolicy -> Maybe Natural -> PlayerLatencyPolicy)
-> Lens
     PlayerLatencyPolicy
     PlayerLatencyPolicy
     (Maybe Natural)
     (Maybe Natural)
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)

-- | 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 :: (Maybe Natural -> f (Maybe Natural))
-> PlayerLatencyPolicy -> f PlayerLatencyPolicy
playerLatencyPolicy_maximumIndividualPlayerLatencyMilliseconds = (PlayerLatencyPolicy -> Maybe Natural)
-> (PlayerLatencyPolicy -> Maybe Natural -> PlayerLatencyPolicy)
-> Lens
     PlayerLatencyPolicy
     PlayerLatencyPolicy
     (Maybe Natural)
     (Maybe Natural)
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)

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

instance Prelude.Hashable PlayerLatencyPolicy

instance Prelude.NFData PlayerLatencyPolicy

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