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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.GameLift.Types.AttributeValue
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 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),
    -- | 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\"}}@.
    --
    -- You can provide up to 10 @PlayerAttributes@.
    Player -> Maybe (HashMap Text AttributeValue)
playerAttributes :: Prelude.Maybe (Prelude.HashMap Prelude.Text AttributeValue),
    -- | A unique identifier for a player
    Player -> Maybe Text
playerId :: Prelude.Maybe Prelude.Text,
    -- | 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
  }
  deriving (Player -> Player -> Bool
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]
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
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. 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:
--
-- '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.
--
-- '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\"}}@.
--
-- You can provide up to 10 @PlayerAttributes@.
--
-- 'playerId', 'player_playerId' - A unique identifier for a player
--
-- '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.
newPlayer ::
  Player
newPlayer :: Player
newPlayer =
  Player'
    { $sel:latencyInMs:Player' :: Maybe (HashMap Text Natural)
latencyInMs = forall a. Maybe a
Prelude.Nothing,
      $sel:playerAttributes:Player' :: Maybe (HashMap Text AttributeValue)
playerAttributes = forall a. Maybe a
Prelude.Nothing,
      $sel:playerId:Player' :: Maybe Text
playerId = forall a. Maybe a
Prelude.Nothing,
      $sel:team:Player' :: Maybe Text
team = forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: Lens' Player (Maybe (HashMap Text Natural))
player_latencyInMs = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | 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\"}}@.
--
-- You can provide up to 10 @PlayerAttributes@.
player_playerAttributes :: Lens.Lens' Player (Prelude.Maybe (Prelude.HashMap Prelude.Text AttributeValue))
player_playerAttributes :: Lens' Player (Maybe (HashMap Text AttributeValue))
player_playerAttributes = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A unique identifier for a player
player_playerId :: Lens.Lens' Player (Prelude.Maybe Prelude.Text)
player_playerId :: Lens' Player (Maybe Text)
player_playerId = 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)

-- | 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 :: Lens' Player (Maybe Text)
player_team = 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)

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

instance Prelude.Hashable Player where
  hashWithSalt :: Int -> Player -> Int
hashWithSalt Int
_salt Player' {Maybe Text
Maybe (HashMap Text Natural)
Maybe (HashMap Text AttributeValue)
team :: Maybe Text
playerId :: Maybe Text
playerAttributes :: Maybe (HashMap Text AttributeValue)
latencyInMs :: Maybe (HashMap Text Natural)
$sel:team:Player' :: Player -> Maybe Text
$sel:playerId:Player' :: Player -> Maybe Text
$sel:playerAttributes:Player' :: Player -> Maybe (HashMap Text AttributeValue)
$sel:latencyInMs:Player' :: Player -> Maybe (HashMap Text Natural)
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Natural)
latencyInMs
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text AttributeValue)
playerAttributes
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
playerId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
team

instance Prelude.NFData Player where
  rnf :: Player -> ()
rnf Player' {Maybe Text
Maybe (HashMap Text Natural)
Maybe (HashMap Text AttributeValue)
team :: Maybe Text
playerId :: Maybe Text
playerAttributes :: Maybe (HashMap Text AttributeValue)
latencyInMs :: Maybe (HashMap Text Natural)
$sel:team:Player' :: Player -> Maybe Text
$sel:playerId:Player' :: Player -> Maybe Text
$sel:playerAttributes:Player' :: Player -> Maybe (HashMap Text AttributeValue)
$sel:latencyInMs:Player' :: Player -> Maybe (HashMap Text Natural)
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Natural)
latencyInMs
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text AttributeValue)
playerAttributes
      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
team

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