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

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

-- | Regional latency information for a player, used when requesting a new
-- game session with StartGameSessionPlacement. 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,
    -- | Name of the Region that is associated with the latency value.
    PlayerLatency -> Maybe Text
regionIdentifier :: Prelude.Maybe Prelude.Text,
    -- | A unique identifier for a player associated with the latency data.
    PlayerLatency -> Maybe Text
playerId :: Prelude.Maybe Prelude.Text
  }
  deriving (PlayerLatency -> PlayerLatency -> Bool
(PlayerLatency -> PlayerLatency -> Bool)
-> (PlayerLatency -> PlayerLatency -> Bool) -> Eq PlayerLatency
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]
(Int -> ReadS PlayerLatency)
-> ReadS [PlayerLatency]
-> ReadPrec PlayerLatency
-> ReadPrec [PlayerLatency]
-> Read 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
(Int -> PlayerLatency -> ShowS)
-> (PlayerLatency -> String)
-> ([PlayerLatency] -> ShowS)
-> Show PlayerLatency
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. PlayerLatency -> Rep PlayerLatency x)
-> (forall x. Rep PlayerLatency x -> PlayerLatency)
-> Generic PlayerLatency
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.
--
-- 'regionIdentifier', 'playerLatency_regionIdentifier' - Name of the Region that is associated with the latency value.
--
-- 'playerId', 'playerLatency_playerId' - A unique identifier for a player associated with the latency data.
newPlayerLatency ::
  PlayerLatency
newPlayerLatency :: PlayerLatency
newPlayerLatency =
  PlayerLatency' :: Maybe Double -> Maybe Text -> Maybe Text -> PlayerLatency
PlayerLatency'
    { $sel:latencyInMilliseconds:PlayerLatency' :: Maybe Double
latencyInMilliseconds =
        Maybe Double
forall a. Maybe a
Prelude.Nothing,
      $sel:regionIdentifier:PlayerLatency' :: Maybe Text
regionIdentifier = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:playerId:PlayerLatency' :: Maybe Text
playerId = Maybe Text
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 :: (Maybe Double -> f (Maybe Double))
-> PlayerLatency -> f PlayerLatency
playerLatency_latencyInMilliseconds = (PlayerLatency -> Maybe Double)
-> (PlayerLatency -> Maybe Double -> PlayerLatency)
-> Lens PlayerLatency PlayerLatency (Maybe Double) (Maybe Double)
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)

-- | Name of the Region that is associated with the latency value.
playerLatency_regionIdentifier :: Lens.Lens' PlayerLatency (Prelude.Maybe Prelude.Text)
playerLatency_regionIdentifier :: (Maybe Text -> f (Maybe Text)) -> PlayerLatency -> f PlayerLatency
playerLatency_regionIdentifier = (PlayerLatency -> Maybe Text)
-> (PlayerLatency -> Maybe Text -> PlayerLatency)
-> Lens PlayerLatency PlayerLatency (Maybe Text) (Maybe Text)
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)

-- | A unique identifier for a player associated with the latency data.
playerLatency_playerId :: Lens.Lens' PlayerLatency (Prelude.Maybe Prelude.Text)
playerLatency_playerId :: (Maybe Text -> f (Maybe Text)) -> PlayerLatency -> f PlayerLatency
playerLatency_playerId = (PlayerLatency -> Maybe Text)
-> (PlayerLatency -> Maybe Text -> PlayerLatency)
-> Lens PlayerLatency PlayerLatency (Maybe Text) (Maybe Text)
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)

instance Core.FromJSON PlayerLatency where
  parseJSON :: Value -> Parser PlayerLatency
parseJSON =
    String
-> (Object -> Parser PlayerLatency)
-> Value
-> Parser PlayerLatency
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"PlayerLatency"
      ( \Object
x ->
          Maybe Double -> Maybe Text -> Maybe Text -> PlayerLatency
PlayerLatency'
            (Maybe Double -> Maybe Text -> Maybe Text -> PlayerLatency)
-> Parser (Maybe Double)
-> Parser (Maybe Text -> Maybe Text -> PlayerLatency)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Double)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"LatencyInMilliseconds")
            Parser (Maybe Text -> Maybe Text -> PlayerLatency)
-> Parser (Maybe Text) -> Parser (Maybe Text -> PlayerLatency)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"RegionIdentifier")
            Parser (Maybe Text -> PlayerLatency)
-> Parser (Maybe Text) -> Parser PlayerLatency
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"PlayerId")
      )

instance Prelude.Hashable PlayerLatency

instance Prelude.NFData PlayerLatency

instance Core.ToJSON PlayerLatency where
  toJSON :: PlayerLatency -> Value
toJSON PlayerLatency' {Maybe Double
Maybe Text
playerId :: Maybe Text
regionIdentifier :: Maybe Text
latencyInMilliseconds :: Maybe Double
$sel:playerId:PlayerLatency' :: PlayerLatency -> Maybe Text
$sel:regionIdentifier:PlayerLatency' :: PlayerLatency -> Maybe Text
$sel:latencyInMilliseconds:PlayerLatency' :: PlayerLatency -> Maybe Double
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"LatencyInMilliseconds" Text -> Double -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Double -> Pair) -> Maybe Double -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Double
latencyInMilliseconds,
            (Text
"RegionIdentifier" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
regionIdentifier,
            (Text
"PlayerId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
playerId
          ]
      )