{-# 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.PlayerLatency
-- 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.PlayerLatency 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

-- | Regional latency information for a player, used when requesting a new
-- game session. This value indicates the amount of time lag that exists
-- when the player is connected to a fleet in the specified Region. The
-- relative difference between a player\'s latency values for multiple
-- Regions are used to determine which fleets are best suited to place a
-- new game session for the player.
--
-- /See:/ 'newPlayerLatency' smart constructor.
data PlayerLatency = PlayerLatency'
  { -- | Amount of time that represents the time lag experienced by the player
    -- when connected to the specified Region.
    PlayerLatency -> Maybe Double
latencyInMilliseconds :: Prelude.Maybe Prelude.Double,
    -- | A unique identifier for a player associated with the latency data.
    PlayerLatency -> Maybe Text
playerId :: Prelude.Maybe Prelude.Text,
    -- | Name of the Region that is associated with the latency value.
    PlayerLatency -> Maybe Text
regionIdentifier :: Prelude.Maybe Prelude.Text
  }
  deriving (PlayerLatency -> PlayerLatency -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PlayerLatency -> PlayerLatency -> Bool
$c/= :: PlayerLatency -> PlayerLatency -> Bool
== :: PlayerLatency -> PlayerLatency -> Bool
$c== :: PlayerLatency -> PlayerLatency -> Bool
Prelude.Eq, ReadPrec [PlayerLatency]
ReadPrec PlayerLatency
Int -> ReadS PlayerLatency
ReadS [PlayerLatency]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PlayerLatency]
$creadListPrec :: ReadPrec [PlayerLatency]
readPrec :: ReadPrec PlayerLatency
$creadPrec :: ReadPrec PlayerLatency
readList :: ReadS [PlayerLatency]
$creadList :: ReadS [PlayerLatency]
readsPrec :: Int -> ReadS PlayerLatency
$creadsPrec :: Int -> ReadS PlayerLatency
Prelude.Read, Int -> PlayerLatency -> ShowS
[PlayerLatency] -> ShowS
PlayerLatency -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PlayerLatency] -> ShowS
$cshowList :: [PlayerLatency] -> ShowS
show :: PlayerLatency -> String
$cshow :: PlayerLatency -> String
showsPrec :: Int -> PlayerLatency -> ShowS
$cshowsPrec :: Int -> PlayerLatency -> ShowS
Prelude.Show, forall x. Rep PlayerLatency x -> PlayerLatency
forall x. PlayerLatency -> Rep PlayerLatency x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PlayerLatency x -> PlayerLatency
$cfrom :: forall x. PlayerLatency -> Rep PlayerLatency x
Prelude.Generic)

-- |
-- Create a value of 'PlayerLatency' 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:
--
-- 'latencyInMilliseconds', 'playerLatency_latencyInMilliseconds' - Amount of time that represents the time lag experienced by the player
-- when connected to the specified Region.
--
-- 'playerId', 'playerLatency_playerId' - A unique identifier for a player associated with the latency data.
--
-- 'regionIdentifier', 'playerLatency_regionIdentifier' - Name of the Region that is associated with the latency value.
newPlayerLatency ::
  PlayerLatency
newPlayerLatency :: PlayerLatency
newPlayerLatency =
  PlayerLatency'
    { $sel:latencyInMilliseconds:PlayerLatency' :: Maybe Double
latencyInMilliseconds =
        forall a. Maybe a
Prelude.Nothing,
      $sel:playerId:PlayerLatency' :: Maybe Text
playerId = forall a. Maybe a
Prelude.Nothing,
      $sel:regionIdentifier:PlayerLatency' :: Maybe Text
regionIdentifier = forall a. Maybe a
Prelude.Nothing
    }

-- | Amount of time that represents the time lag experienced by the player
-- when connected to the specified Region.
playerLatency_latencyInMilliseconds :: Lens.Lens' PlayerLatency (Prelude.Maybe Prelude.Double)
playerLatency_latencyInMilliseconds :: Lens' PlayerLatency (Maybe Double)
playerLatency_latencyInMilliseconds = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PlayerLatency' {Maybe Double
latencyInMilliseconds :: Maybe Double
$sel:latencyInMilliseconds:PlayerLatency' :: PlayerLatency -> Maybe Double
latencyInMilliseconds} -> Maybe Double
latencyInMilliseconds) (\s :: PlayerLatency
s@PlayerLatency' {} Maybe Double
a -> PlayerLatency
s {$sel:latencyInMilliseconds:PlayerLatency' :: Maybe Double
latencyInMilliseconds = Maybe Double
a} :: PlayerLatency)

-- | A unique identifier for a player associated with the latency data.
playerLatency_playerId :: Lens.Lens' PlayerLatency (Prelude.Maybe Prelude.Text)
playerLatency_playerId :: Lens' PlayerLatency (Maybe Text)
playerLatency_playerId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PlayerLatency' {Maybe Text
playerId :: Maybe Text
$sel:playerId:PlayerLatency' :: PlayerLatency -> Maybe Text
playerId} -> Maybe Text
playerId) (\s :: PlayerLatency
s@PlayerLatency' {} Maybe Text
a -> PlayerLatency
s {$sel:playerId:PlayerLatency' :: Maybe Text
playerId = Maybe Text
a} :: PlayerLatency)

-- | Name of the Region that is associated with the latency value.
playerLatency_regionIdentifier :: Lens.Lens' PlayerLatency (Prelude.Maybe Prelude.Text)
playerLatency_regionIdentifier :: Lens' PlayerLatency (Maybe Text)
playerLatency_regionIdentifier = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PlayerLatency' {Maybe Text
regionIdentifier :: Maybe Text
$sel:regionIdentifier:PlayerLatency' :: PlayerLatency -> Maybe Text
regionIdentifier} -> Maybe Text
regionIdentifier) (\s :: PlayerLatency
s@PlayerLatency' {} Maybe Text
a -> PlayerLatency
s {$sel:regionIdentifier:PlayerLatency' :: Maybe Text
regionIdentifier = Maybe Text
a} :: PlayerLatency)

instance Data.FromJSON PlayerLatency where
  parseJSON :: Value -> Parser PlayerLatency
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"PlayerLatency"
      ( \Object
x ->
          Maybe Double -> Maybe Text -> Maybe Text -> PlayerLatency
PlayerLatency'
            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
"LatencyInMilliseconds")
            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
"PlayerId")
            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
"RegionIdentifier")
      )

instance Prelude.Hashable PlayerLatency where
  hashWithSalt :: Int -> PlayerLatency -> Int
hashWithSalt Int
_salt PlayerLatency' {Maybe Double
Maybe Text
regionIdentifier :: Maybe Text
playerId :: Maybe Text
latencyInMilliseconds :: Maybe Double
$sel:regionIdentifier:PlayerLatency' :: PlayerLatency -> Maybe Text
$sel:playerId:PlayerLatency' :: PlayerLatency -> Maybe Text
$sel:latencyInMilliseconds:PlayerLatency' :: PlayerLatency -> Maybe Double
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Double
latencyInMilliseconds
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
playerId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
regionIdentifier

instance Prelude.NFData PlayerLatency where
  rnf :: PlayerLatency -> ()
rnf PlayerLatency' {Maybe Double
Maybe Text
regionIdentifier :: Maybe Text
playerId :: Maybe Text
latencyInMilliseconds :: Maybe Double
$sel:regionIdentifier:PlayerLatency' :: PlayerLatency -> Maybe Text
$sel:playerId:PlayerLatency' :: PlayerLatency -> Maybe Text
$sel:latencyInMilliseconds:PlayerLatency' :: PlayerLatency -> Maybe Double
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Double
latencyInMilliseconds
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
playerId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
regionIdentifier

instance Data.ToJSON PlayerLatency where
  toJSON :: PlayerLatency -> Value
toJSON PlayerLatency' {Maybe Double
Maybe Text
regionIdentifier :: Maybe Text
playerId :: Maybe Text
latencyInMilliseconds :: Maybe Double
$sel:regionIdentifier:PlayerLatency' :: PlayerLatency -> Maybe Text
$sel:playerId:PlayerLatency' :: PlayerLatency -> Maybe Text
$sel:latencyInMilliseconds:PlayerLatency' :: PlayerLatency -> Maybe Double
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"LatencyInMilliseconds" 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 Double
latencyInMilliseconds,
            (Key
"PlayerId" 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 Text
playerId,
            (Key
"RegionIdentifier" 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 Text
regionIdentifier
          ]
      )