{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.CreatePlayerSession
-- 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)
--
-- Reserves an open player slot in a game session for a player. New player
-- sessions can be created in any game session with an open slot that is in
-- @ACTIVE@ status and has a player creation policy of @ACCEPT_ALL@. You
-- can add a group of players to a game session with CreatePlayerSessions.
--
-- To create a player session, specify a game session ID, player ID, and
-- optionally a set of player data.
--
-- If successful, a slot is reserved in the game session for the player and
-- a new PlayerSession object is returned with a player session ID. The
-- player references the player session ID when sending a connection
-- request to the game session, and the game server can use it to validate
-- the player reservation with the GameLift service. Player sessions cannot
-- be updated.
--
-- /Available in Amazon GameLift Local./
--
-- __Related actions__
--
-- CreatePlayerSession | CreatePlayerSessions | DescribePlayerSessions |
-- StartGameSessionPlacement | DescribeGameSessionPlacement |
-- <https://docs.aws.amazon.com/gamelift/latest/developerguide/reference-awssdk.html#reference-awssdk-resources-fleets All APIs by task>
module Amazonka.GameLift.CreatePlayerSession
  ( -- * Creating a Request
    CreatePlayerSession (..),
    newCreatePlayerSession,

    -- * Request Lenses
    createPlayerSession_playerData,
    createPlayerSession_gameSessionId,
    createPlayerSession_playerId,

    -- * Destructuring the Response
    CreatePlayerSessionResponse (..),
    newCreatePlayerSessionResponse,

    -- * Response Lenses
    createPlayerSessionResponse_playerSession,
    createPlayerSessionResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.GameLift.Types
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | Represents the input for a request operation.
--
-- /See:/ 'newCreatePlayerSession' smart constructor.
data CreatePlayerSession = CreatePlayerSession'
  { -- | Developer-defined information related to a player. GameLift does not use
    -- this data, so it can be formatted as needed for use in the game.
    CreatePlayerSession -> Maybe Text
playerData :: Prelude.Maybe Prelude.Text,
    -- | A unique identifier for the game session to add a player to.
    CreatePlayerSession -> Text
gameSessionId :: Prelude.Text,
    -- | A unique identifier for a player. Player IDs are developer-defined.
    CreatePlayerSession -> Text
playerId :: Prelude.Text
  }
  deriving (CreatePlayerSession -> CreatePlayerSession -> Bool
(CreatePlayerSession -> CreatePlayerSession -> Bool)
-> (CreatePlayerSession -> CreatePlayerSession -> Bool)
-> Eq CreatePlayerSession
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreatePlayerSession -> CreatePlayerSession -> Bool
$c/= :: CreatePlayerSession -> CreatePlayerSession -> Bool
== :: CreatePlayerSession -> CreatePlayerSession -> Bool
$c== :: CreatePlayerSession -> CreatePlayerSession -> Bool
Prelude.Eq, ReadPrec [CreatePlayerSession]
ReadPrec CreatePlayerSession
Int -> ReadS CreatePlayerSession
ReadS [CreatePlayerSession]
(Int -> ReadS CreatePlayerSession)
-> ReadS [CreatePlayerSession]
-> ReadPrec CreatePlayerSession
-> ReadPrec [CreatePlayerSession]
-> Read CreatePlayerSession
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreatePlayerSession]
$creadListPrec :: ReadPrec [CreatePlayerSession]
readPrec :: ReadPrec CreatePlayerSession
$creadPrec :: ReadPrec CreatePlayerSession
readList :: ReadS [CreatePlayerSession]
$creadList :: ReadS [CreatePlayerSession]
readsPrec :: Int -> ReadS CreatePlayerSession
$creadsPrec :: Int -> ReadS CreatePlayerSession
Prelude.Read, Int -> CreatePlayerSession -> ShowS
[CreatePlayerSession] -> ShowS
CreatePlayerSession -> String
(Int -> CreatePlayerSession -> ShowS)
-> (CreatePlayerSession -> String)
-> ([CreatePlayerSession] -> ShowS)
-> Show CreatePlayerSession
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreatePlayerSession] -> ShowS
$cshowList :: [CreatePlayerSession] -> ShowS
show :: CreatePlayerSession -> String
$cshow :: CreatePlayerSession -> String
showsPrec :: Int -> CreatePlayerSession -> ShowS
$cshowsPrec :: Int -> CreatePlayerSession -> ShowS
Prelude.Show, (forall x. CreatePlayerSession -> Rep CreatePlayerSession x)
-> (forall x. Rep CreatePlayerSession x -> CreatePlayerSession)
-> Generic CreatePlayerSession
forall x. Rep CreatePlayerSession x -> CreatePlayerSession
forall x. CreatePlayerSession -> Rep CreatePlayerSession x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreatePlayerSession x -> CreatePlayerSession
$cfrom :: forall x. CreatePlayerSession -> Rep CreatePlayerSession x
Prelude.Generic)

-- |
-- Create a value of 'CreatePlayerSession' 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:
--
-- 'playerData', 'createPlayerSession_playerData' - Developer-defined information related to a player. GameLift does not use
-- this data, so it can be formatted as needed for use in the game.
--
-- 'gameSessionId', 'createPlayerSession_gameSessionId' - A unique identifier for the game session to add a player to.
--
-- 'playerId', 'createPlayerSession_playerId' - A unique identifier for a player. Player IDs are developer-defined.
newCreatePlayerSession ::
  -- | 'gameSessionId'
  Prelude.Text ->
  -- | 'playerId'
  Prelude.Text ->
  CreatePlayerSession
newCreatePlayerSession :: Text -> Text -> CreatePlayerSession
newCreatePlayerSession Text
pGameSessionId_ Text
pPlayerId_ =
  CreatePlayerSession' :: Maybe Text -> Text -> Text -> CreatePlayerSession
CreatePlayerSession'
    { $sel:playerData:CreatePlayerSession' :: Maybe Text
playerData = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:gameSessionId:CreatePlayerSession' :: Text
gameSessionId = Text
pGameSessionId_,
      $sel:playerId:CreatePlayerSession' :: Text
playerId = Text
pPlayerId_
    }

-- | Developer-defined information related to a player. GameLift does not use
-- this data, so it can be formatted as needed for use in the game.
createPlayerSession_playerData :: Lens.Lens' CreatePlayerSession (Prelude.Maybe Prelude.Text)
createPlayerSession_playerData :: (Maybe Text -> f (Maybe Text))
-> CreatePlayerSession -> f CreatePlayerSession
createPlayerSession_playerData = (CreatePlayerSession -> Maybe Text)
-> (CreatePlayerSession -> Maybe Text -> CreatePlayerSession)
-> Lens
     CreatePlayerSession CreatePlayerSession (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreatePlayerSession' {Maybe Text
playerData :: Maybe Text
$sel:playerData:CreatePlayerSession' :: CreatePlayerSession -> Maybe Text
playerData} -> Maybe Text
playerData) (\s :: CreatePlayerSession
s@CreatePlayerSession' {} Maybe Text
a -> CreatePlayerSession
s {$sel:playerData:CreatePlayerSession' :: Maybe Text
playerData = Maybe Text
a} :: CreatePlayerSession)

-- | A unique identifier for the game session to add a player to.
createPlayerSession_gameSessionId :: Lens.Lens' CreatePlayerSession Prelude.Text
createPlayerSession_gameSessionId :: (Text -> f Text) -> CreatePlayerSession -> f CreatePlayerSession
createPlayerSession_gameSessionId = (CreatePlayerSession -> Text)
-> (CreatePlayerSession -> Text -> CreatePlayerSession)
-> Lens CreatePlayerSession CreatePlayerSession Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreatePlayerSession' {Text
gameSessionId :: Text
$sel:gameSessionId:CreatePlayerSession' :: CreatePlayerSession -> Text
gameSessionId} -> Text
gameSessionId) (\s :: CreatePlayerSession
s@CreatePlayerSession' {} Text
a -> CreatePlayerSession
s {$sel:gameSessionId:CreatePlayerSession' :: Text
gameSessionId = Text
a} :: CreatePlayerSession)

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

instance Core.AWSRequest CreatePlayerSession where
  type
    AWSResponse CreatePlayerSession =
      CreatePlayerSessionResponse
  request :: CreatePlayerSession -> Request CreatePlayerSession
request = Service -> CreatePlayerSession -> Request CreatePlayerSession
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreatePlayerSession
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreatePlayerSession)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreatePlayerSession))
-> Logger
-> Service
-> Proxy CreatePlayerSession
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreatePlayerSession)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe PlayerSession -> Int -> CreatePlayerSessionResponse
CreatePlayerSessionResponse'
            (Maybe PlayerSession -> Int -> CreatePlayerSessionResponse)
-> Either String (Maybe PlayerSession)
-> Either String (Int -> CreatePlayerSessionResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe PlayerSession)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"PlayerSession")
            Either String (Int -> CreatePlayerSessionResponse)
-> Either String Int -> Either String CreatePlayerSessionResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable CreatePlayerSession

instance Prelude.NFData CreatePlayerSession

instance Core.ToHeaders CreatePlayerSession where
  toHeaders :: CreatePlayerSession -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreatePlayerSession -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"GameLift.CreatePlayerSession" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON CreatePlayerSession where
  toJSON :: CreatePlayerSession -> Value
toJSON CreatePlayerSession' {Maybe Text
Text
playerId :: Text
gameSessionId :: Text
playerData :: Maybe Text
$sel:playerId:CreatePlayerSession' :: CreatePlayerSession -> Text
$sel:gameSessionId:CreatePlayerSession' :: CreatePlayerSession -> Text
$sel:playerData:CreatePlayerSession' :: CreatePlayerSession -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"PlayerData" 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
playerData,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"GameSessionId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
gameSessionId),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"PlayerId" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
playerId)
          ]
      )

instance Core.ToPath CreatePlayerSession where
  toPath :: CreatePlayerSession -> ByteString
toPath = ByteString -> CreatePlayerSession -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery CreatePlayerSession where
  toQuery :: CreatePlayerSession -> QueryString
toQuery = QueryString -> CreatePlayerSession -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | Represents the returned data in response to a request operation.
--
-- /See:/ 'newCreatePlayerSessionResponse' smart constructor.
data CreatePlayerSessionResponse = CreatePlayerSessionResponse'
  { -- | Object that describes the newly created player session record.
    CreatePlayerSessionResponse -> Maybe PlayerSession
playerSession :: Prelude.Maybe PlayerSession,
    -- | The response's http status code.
    CreatePlayerSessionResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (CreatePlayerSessionResponse -> CreatePlayerSessionResponse -> Bool
(CreatePlayerSessionResponse
 -> CreatePlayerSessionResponse -> Bool)
-> (CreatePlayerSessionResponse
    -> CreatePlayerSessionResponse -> Bool)
-> Eq CreatePlayerSessionResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreatePlayerSessionResponse -> CreatePlayerSessionResponse -> Bool
$c/= :: CreatePlayerSessionResponse -> CreatePlayerSessionResponse -> Bool
== :: CreatePlayerSessionResponse -> CreatePlayerSessionResponse -> Bool
$c== :: CreatePlayerSessionResponse -> CreatePlayerSessionResponse -> Bool
Prelude.Eq, ReadPrec [CreatePlayerSessionResponse]
ReadPrec CreatePlayerSessionResponse
Int -> ReadS CreatePlayerSessionResponse
ReadS [CreatePlayerSessionResponse]
(Int -> ReadS CreatePlayerSessionResponse)
-> ReadS [CreatePlayerSessionResponse]
-> ReadPrec CreatePlayerSessionResponse
-> ReadPrec [CreatePlayerSessionResponse]
-> Read CreatePlayerSessionResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreatePlayerSessionResponse]
$creadListPrec :: ReadPrec [CreatePlayerSessionResponse]
readPrec :: ReadPrec CreatePlayerSessionResponse
$creadPrec :: ReadPrec CreatePlayerSessionResponse
readList :: ReadS [CreatePlayerSessionResponse]
$creadList :: ReadS [CreatePlayerSessionResponse]
readsPrec :: Int -> ReadS CreatePlayerSessionResponse
$creadsPrec :: Int -> ReadS CreatePlayerSessionResponse
Prelude.Read, Int -> CreatePlayerSessionResponse -> ShowS
[CreatePlayerSessionResponse] -> ShowS
CreatePlayerSessionResponse -> String
(Int -> CreatePlayerSessionResponse -> ShowS)
-> (CreatePlayerSessionResponse -> String)
-> ([CreatePlayerSessionResponse] -> ShowS)
-> Show CreatePlayerSessionResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreatePlayerSessionResponse] -> ShowS
$cshowList :: [CreatePlayerSessionResponse] -> ShowS
show :: CreatePlayerSessionResponse -> String
$cshow :: CreatePlayerSessionResponse -> String
showsPrec :: Int -> CreatePlayerSessionResponse -> ShowS
$cshowsPrec :: Int -> CreatePlayerSessionResponse -> ShowS
Prelude.Show, (forall x.
 CreatePlayerSessionResponse -> Rep CreatePlayerSessionResponse x)
-> (forall x.
    Rep CreatePlayerSessionResponse x -> CreatePlayerSessionResponse)
-> Generic CreatePlayerSessionResponse
forall x.
Rep CreatePlayerSessionResponse x -> CreatePlayerSessionResponse
forall x.
CreatePlayerSessionResponse -> Rep CreatePlayerSessionResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CreatePlayerSessionResponse x -> CreatePlayerSessionResponse
$cfrom :: forall x.
CreatePlayerSessionResponse -> Rep CreatePlayerSessionResponse x
Prelude.Generic)

-- |
-- Create a value of 'CreatePlayerSessionResponse' 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:
--
-- 'playerSession', 'createPlayerSessionResponse_playerSession' - Object that describes the newly created player session record.
--
-- 'httpStatus', 'createPlayerSessionResponse_httpStatus' - The response's http status code.
newCreatePlayerSessionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  CreatePlayerSessionResponse
newCreatePlayerSessionResponse :: Int -> CreatePlayerSessionResponse
newCreatePlayerSessionResponse Int
pHttpStatus_ =
  CreatePlayerSessionResponse' :: Maybe PlayerSession -> Int -> CreatePlayerSessionResponse
CreatePlayerSessionResponse'
    { $sel:playerSession:CreatePlayerSessionResponse' :: Maybe PlayerSession
playerSession =
        Maybe PlayerSession
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:CreatePlayerSessionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | Object that describes the newly created player session record.
createPlayerSessionResponse_playerSession :: Lens.Lens' CreatePlayerSessionResponse (Prelude.Maybe PlayerSession)
createPlayerSessionResponse_playerSession :: (Maybe PlayerSession -> f (Maybe PlayerSession))
-> CreatePlayerSessionResponse -> f CreatePlayerSessionResponse
createPlayerSessionResponse_playerSession = (CreatePlayerSessionResponse -> Maybe PlayerSession)
-> (CreatePlayerSessionResponse
    -> Maybe PlayerSession -> CreatePlayerSessionResponse)
-> Lens
     CreatePlayerSessionResponse
     CreatePlayerSessionResponse
     (Maybe PlayerSession)
     (Maybe PlayerSession)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreatePlayerSessionResponse' {Maybe PlayerSession
playerSession :: Maybe PlayerSession
$sel:playerSession:CreatePlayerSessionResponse' :: CreatePlayerSessionResponse -> Maybe PlayerSession
playerSession} -> Maybe PlayerSession
playerSession) (\s :: CreatePlayerSessionResponse
s@CreatePlayerSessionResponse' {} Maybe PlayerSession
a -> CreatePlayerSessionResponse
s {$sel:playerSession:CreatePlayerSessionResponse' :: Maybe PlayerSession
playerSession = Maybe PlayerSession
a} :: CreatePlayerSessionResponse)

-- | The response's http status code.
createPlayerSessionResponse_httpStatus :: Lens.Lens' CreatePlayerSessionResponse Prelude.Int
createPlayerSessionResponse_httpStatus :: (Int -> f Int)
-> CreatePlayerSessionResponse -> f CreatePlayerSessionResponse
createPlayerSessionResponse_httpStatus = (CreatePlayerSessionResponse -> Int)
-> (CreatePlayerSessionResponse
    -> Int -> CreatePlayerSessionResponse)
-> Lens
     CreatePlayerSessionResponse CreatePlayerSessionResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreatePlayerSessionResponse' {Int
httpStatus :: Int
$sel:httpStatus:CreatePlayerSessionResponse' :: CreatePlayerSessionResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: CreatePlayerSessionResponse
s@CreatePlayerSessionResponse' {} Int
a -> CreatePlayerSessionResponse
s {$sel:httpStatus:CreatePlayerSessionResponse' :: Int
httpStatus = Int
a} :: CreatePlayerSessionResponse)

instance Prelude.NFData CreatePlayerSessionResponse