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

import qualified Amazonka.Core as Core
import Amazonka.GameLift.Types.AttributeValue
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Represents a player in matchmaking. When starting a matchmaking request,
-- a player has a player ID, attributes, and may have latency data. Team
-- information is added after a match has been successfully completed.
--
-- /See:/ 'newPlayer' smart constructor.
data Player = Player'
  { -- | A collection of key:value pairs containing player information for use in
    -- matchmaking. Player attribute keys must match the /playerAttributes/
    -- used in a matchmaking rule set. Example:
    -- @\"PlayerAttributes\": {\"skill\": {\"N\": \"23\"}, \"gameMode\": {\"S\": \"deathmatch\"}}@.
    Player -> Maybe (HashMap Text AttributeValue)
playerAttributes :: Prelude.Maybe (Prelude.HashMap Prelude.Text AttributeValue),
    -- | Name of the team that the player is assigned to in a match. Team names
    -- are defined in a matchmaking rule set.
    Player -> Maybe Text
team :: Prelude.Maybe Prelude.Text,
    -- | A unique identifier for a player
    Player -> Maybe Text
playerId :: Prelude.Maybe Prelude.Text,
    -- | A set of values, expressed in milliseconds, that indicates the amount of
    -- latency that a player experiences when connected to AWS Regions. If this
    -- property is present, FlexMatch considers placing the match only in
    -- Regions for which latency is reported.
    --
    -- If a matchmaker has a rule that evaluates player latency, players must
    -- report latency in order to be matched. If no latency is reported in this
    -- scenario, FlexMatch assumes that no Regions are available to the player
    -- and the ticket is not matchable.
    Player -> Maybe (HashMap Text Natural)
latencyInMs :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Natural)
  }
  deriving (Player -> Player -> Bool
(Player -> Player -> Bool)
-> (Player -> Player -> Bool) -> Eq Player
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Player -> Player -> Bool
$c/= :: Player -> Player -> Bool
== :: Player -> Player -> Bool
$c== :: Player -> Player -> Bool
Prelude.Eq, ReadPrec [Player]
ReadPrec Player
Int -> ReadS Player
ReadS [Player]
(Int -> ReadS Player)
-> ReadS [Player]
-> ReadPrec Player
-> ReadPrec [Player]
-> Read Player
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Player]
$creadListPrec :: ReadPrec [Player]
readPrec :: ReadPrec Player
$creadPrec :: ReadPrec Player
readList :: ReadS [Player]
$creadList :: ReadS [Player]
readsPrec :: Int -> ReadS Player
$creadsPrec :: Int -> ReadS Player
Prelude.Read, Int -> Player -> ShowS
[Player] -> ShowS
Player -> String
(Int -> Player -> ShowS)
-> (Player -> String) -> ([Player] -> ShowS) -> Show Player
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Player] -> ShowS
$cshowList :: [Player] -> ShowS
show :: Player -> String
$cshow :: Player -> String
showsPrec :: Int -> Player -> ShowS
$cshowsPrec :: Int -> Player -> ShowS
Prelude.Show, (forall x. Player -> Rep Player x)
-> (forall x. Rep Player x -> Player) -> Generic Player
forall x. Rep Player x -> Player
forall x. Player -> Rep Player x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Player x -> Player
$cfrom :: forall x. Player -> Rep Player x
Prelude.Generic)

-- |
-- Create a value of 'Player' 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:
--
-- 'playerAttributes', 'player_playerAttributes' - A collection of key:value pairs containing player information for use in
-- matchmaking. Player attribute keys must match the /playerAttributes/
-- used in a matchmaking rule set. Example:
-- @\"PlayerAttributes\": {\"skill\": {\"N\": \"23\"}, \"gameMode\": {\"S\": \"deathmatch\"}}@.
--
-- 'team', 'player_team' - Name of the team that the player is assigned to in a match. Team names
-- are defined in a matchmaking rule set.
--
-- 'playerId', 'player_playerId' - A unique identifier for a player
--
-- 'latencyInMs', 'player_latencyInMs' - A set of values, expressed in milliseconds, that indicates the amount of
-- latency that a player experiences when connected to AWS Regions. If this
-- property is present, FlexMatch considers placing the match only in
-- Regions for which latency is reported.
--
-- If a matchmaker has a rule that evaluates player latency, players must
-- report latency in order to be matched. If no latency is reported in this
-- scenario, FlexMatch assumes that no Regions are available to the player
-- and the ticket is not matchable.
newPlayer ::
  Player
newPlayer :: Player
newPlayer =
  Player' :: Maybe (HashMap Text AttributeValue)
-> Maybe Text
-> Maybe Text
-> Maybe (HashMap Text Natural)
-> Player
Player'
    { $sel:playerAttributes:Player' :: Maybe (HashMap Text AttributeValue)
playerAttributes = Maybe (HashMap Text AttributeValue)
forall a. Maybe a
Prelude.Nothing,
      $sel:team:Player' :: Maybe Text
team = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:playerId:Player' :: Maybe Text
playerId = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:latencyInMs:Player' :: Maybe (HashMap Text Natural)
latencyInMs = Maybe (HashMap Text Natural)
forall a. Maybe a
Prelude.Nothing
    }

-- | A collection of key:value pairs containing player information for use in
-- matchmaking. Player attribute keys must match the /playerAttributes/
-- used in a matchmaking rule set. Example:
-- @\"PlayerAttributes\": {\"skill\": {\"N\": \"23\"}, \"gameMode\": {\"S\": \"deathmatch\"}}@.
player_playerAttributes :: Lens.Lens' Player (Prelude.Maybe (Prelude.HashMap Prelude.Text AttributeValue))
player_playerAttributes :: (Maybe (HashMap Text AttributeValue)
 -> f (Maybe (HashMap Text AttributeValue)))
-> Player -> f Player
player_playerAttributes = (Player -> Maybe (HashMap Text AttributeValue))
-> (Player -> Maybe (HashMap Text AttributeValue) -> Player)
-> Lens
     Player
     Player
     (Maybe (HashMap Text AttributeValue))
     (Maybe (HashMap Text AttributeValue))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Player' {Maybe (HashMap Text AttributeValue)
playerAttributes :: Maybe (HashMap Text AttributeValue)
$sel:playerAttributes:Player' :: Player -> Maybe (HashMap Text AttributeValue)
playerAttributes} -> Maybe (HashMap Text AttributeValue)
playerAttributes) (\s :: Player
s@Player' {} Maybe (HashMap Text AttributeValue)
a -> Player
s {$sel:playerAttributes:Player' :: Maybe (HashMap Text AttributeValue)
playerAttributes = Maybe (HashMap Text AttributeValue)
a} :: Player) ((Maybe (HashMap Text AttributeValue)
  -> f (Maybe (HashMap Text AttributeValue)))
 -> Player -> f Player)
-> ((Maybe (HashMap Text AttributeValue)
     -> f (Maybe (HashMap Text AttributeValue)))
    -> Maybe (HashMap Text AttributeValue)
    -> f (Maybe (HashMap Text AttributeValue)))
-> (Maybe (HashMap Text AttributeValue)
    -> f (Maybe (HashMap Text AttributeValue)))
-> Player
-> f Player
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text AttributeValue)
  (HashMap Text AttributeValue)
  (HashMap Text AttributeValue)
  (HashMap Text AttributeValue)
-> Iso
     (Maybe (HashMap Text AttributeValue))
     (Maybe (HashMap Text AttributeValue))
     (Maybe (HashMap Text AttributeValue))
     (Maybe (HashMap Text AttributeValue))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (HashMap Text AttributeValue)
  (HashMap Text AttributeValue)
  (HashMap Text AttributeValue)
  (HashMap Text AttributeValue)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | Name of the team that the player is assigned to in a match. Team names
-- are defined in a matchmaking rule set.
player_team :: Lens.Lens' Player (Prelude.Maybe Prelude.Text)
player_team :: (Maybe Text -> f (Maybe Text)) -> Player -> f Player
player_team = (Player -> Maybe Text)
-> (Player -> Maybe Text -> Player)
-> Lens Player Player (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Player' {Maybe Text
team :: Maybe Text
$sel:team:Player' :: Player -> Maybe Text
team} -> Maybe Text
team) (\s :: Player
s@Player' {} Maybe Text
a -> Player
s {$sel:team:Player' :: Maybe Text
team = Maybe Text
a} :: Player)

-- | A unique identifier for a player
player_playerId :: Lens.Lens' Player (Prelude.Maybe Prelude.Text)
player_playerId :: (Maybe Text -> f (Maybe Text)) -> Player -> f Player
player_playerId = (Player -> Maybe Text)
-> (Player -> Maybe Text -> Player)
-> Lens Player Player (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Player' {Maybe Text
playerId :: Maybe Text
$sel:playerId:Player' :: Player -> Maybe Text
playerId} -> Maybe Text
playerId) (\s :: Player
s@Player' {} Maybe Text
a -> Player
s {$sel:playerId:Player' :: Maybe Text
playerId = Maybe Text
a} :: Player)

-- | A set of values, expressed in milliseconds, that indicates the amount of
-- latency that a player experiences when connected to AWS Regions. If this
-- property is present, FlexMatch considers placing the match only in
-- Regions for which latency is reported.
--
-- If a matchmaker has a rule that evaluates player latency, players must
-- report latency in order to be matched. If no latency is reported in this
-- scenario, FlexMatch assumes that no Regions are available to the player
-- and the ticket is not matchable.
player_latencyInMs :: Lens.Lens' Player (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Natural))
player_latencyInMs :: (Maybe (HashMap Text Natural) -> f (Maybe (HashMap Text Natural)))
-> Player -> f Player
player_latencyInMs = (Player -> Maybe (HashMap Text Natural))
-> (Player -> Maybe (HashMap Text Natural) -> Player)
-> Lens
     Player
     Player
     (Maybe (HashMap Text Natural))
     (Maybe (HashMap Text Natural))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Player' {Maybe (HashMap Text Natural)
latencyInMs :: Maybe (HashMap Text Natural)
$sel:latencyInMs:Player' :: Player -> Maybe (HashMap Text Natural)
latencyInMs} -> Maybe (HashMap Text Natural)
latencyInMs) (\s :: Player
s@Player' {} Maybe (HashMap Text Natural)
a -> Player
s {$sel:latencyInMs:Player' :: Maybe (HashMap Text Natural)
latencyInMs = Maybe (HashMap Text Natural)
a} :: Player) ((Maybe (HashMap Text Natural) -> f (Maybe (HashMap Text Natural)))
 -> Player -> f Player)
-> ((Maybe (HashMap Text Natural)
     -> f (Maybe (HashMap Text Natural)))
    -> Maybe (HashMap Text Natural)
    -> f (Maybe (HashMap Text Natural)))
-> (Maybe (HashMap Text Natural)
    -> f (Maybe (HashMap Text Natural)))
-> Player
-> f Player
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Natural)
  (HashMap Text Natural)
  (HashMap Text Natural)
  (HashMap Text Natural)
-> Iso
     (Maybe (HashMap Text Natural))
     (Maybe (HashMap Text Natural))
     (Maybe (HashMap Text Natural))
     (Maybe (HashMap Text Natural))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (HashMap Text Natural)
  (HashMap Text Natural)
  (HashMap Text Natural)
  (HashMap Text Natural)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON Player where
  parseJSON :: Value -> Parser Player
parseJSON =
    String -> (Object -> Parser Player) -> Value -> Parser Player
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Player"
      ( \Object
x ->
          Maybe (HashMap Text AttributeValue)
-> Maybe Text
-> Maybe Text
-> Maybe (HashMap Text Natural)
-> Player
Player'
            (Maybe (HashMap Text AttributeValue)
 -> Maybe Text
 -> Maybe Text
 -> Maybe (HashMap Text Natural)
 -> Player)
-> Parser (Maybe (HashMap Text AttributeValue))
-> Parser
     (Maybe Text
      -> Maybe Text -> Maybe (HashMap Text Natural) -> Player)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( Object
x Object
-> Text -> Parser (Maybe (Maybe (HashMap Text AttributeValue)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"PlayerAttributes"
                            Parser (Maybe (Maybe (HashMap Text AttributeValue)))
-> Maybe (HashMap Text AttributeValue)
-> Parser (Maybe (HashMap Text AttributeValue))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text AttributeValue)
forall a. Monoid a => a
Prelude.mempty
                        )
            Parser
  (Maybe Text
   -> Maybe Text -> Maybe (HashMap Text Natural) -> Player)
-> Parser (Maybe Text)
-> Parser (Maybe Text -> Maybe (HashMap Text Natural) -> Player)
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
"Team")
            Parser (Maybe Text -> Maybe (HashMap Text Natural) -> Player)
-> Parser (Maybe Text)
-> Parser (Maybe (HashMap Text Natural) -> Player)
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")
            Parser (Maybe (HashMap Text Natural) -> Player)
-> Parser (Maybe (HashMap Text Natural)) -> Parser Player
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe (HashMap Text Natural)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"LatencyInMs" Parser (Maybe (Maybe (HashMap Text Natural)))
-> Maybe (HashMap Text Natural)
-> Parser (Maybe (HashMap Text Natural))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text Natural)
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable Player

instance Prelude.NFData Player

instance Core.ToJSON Player where
  toJSON :: Player -> Value
toJSON Player' {Maybe Text
Maybe (HashMap Text Natural)
Maybe (HashMap Text AttributeValue)
latencyInMs :: Maybe (HashMap Text Natural)
playerId :: Maybe Text
team :: Maybe Text
playerAttributes :: Maybe (HashMap Text AttributeValue)
$sel:latencyInMs:Player' :: Player -> Maybe (HashMap Text Natural)
$sel:playerId:Player' :: Player -> Maybe Text
$sel:team:Player' :: Player -> Maybe Text
$sel:playerAttributes:Player' :: Player -> Maybe (HashMap Text AttributeValue)
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"PlayerAttributes" Text -> HashMap Text AttributeValue -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (HashMap Text AttributeValue -> Pair)
-> Maybe (HashMap Text AttributeValue) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text AttributeValue)
playerAttributes,
            (Text
"Team" 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
team,
            (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,
            (Text
"LatencyInMs" Text -> HashMap Text Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (HashMap Text Natural -> Pair)
-> Maybe (HashMap Text Natural) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Natural)
latencyInMs
          ]
      )