using System.Threading.Tasks; using System.Collections.Generic; using Unity.Services.Lobbies.Models; using Unity.Services.Lobbies.Http; using TaskScheduler = Unity.Services.Lobbies.Scheduler.TaskScheduler; using Unity.Services.Authentication.Internal; using Unity.Services.Lobbies.Lobby; namespace Unity.Services.Lobbies.Apis.Lobby { public interface ILobbyApiClient { /// /// Async Operation. /// Create a lobby /// /// Request object for CreateLobby /// Configuration for CreateLobby /// Task for a Response object containing status code, headers, and Lobby object /// An exception containing the HttpClientResponse with headers, response code, and string of error. Task> CreateLobbyAsync(CreateLobbyRequest request, Configuration operationConfiguration = null); /// /// Async Operation. /// Delete a lobby /// /// Request object for DeleteLobby /// Configuration for DeleteLobby /// Task for a Response object containing status code, headers /// An exception containing the HttpClientResponse with headers, response code, and string of error. Task DeleteLobbyAsync(DeleteLobbyRequest request, Configuration operationConfiguration = null); /// /// Async Operation. /// Get lobby details /// /// Request object for GetLobby /// Configuration for GetLobby /// Task for a Response object containing status code, headers, and Lobby object /// An exception containing the HttpClientResponse with headers, response code, and string of error. Task> GetLobbyAsync(GetLobbyRequest request, Configuration operationConfiguration = null); /// /// Async Operation. /// Heartbeat a lobby /// /// Request object for Heartbeat /// Configuration for Heartbeat /// Task for a Response object containing status code, headers /// An exception containing the HttpClientResponse with headers, response code, and string of error. Task HeartbeatAsync(HeartbeatRequest request, Configuration operationConfiguration = null); /// /// Async Operation. /// Join a lobby with lobby code /// /// Request object for JoinLobbyByCode /// Configuration for JoinLobbyByCode /// Task for a Response object containing status code, headers, and Lobby object /// An exception containing the HttpClientResponse with headers, response code, and string of error. Task> JoinLobbyByCodeAsync(JoinLobbyByCodeRequest request, Configuration operationConfiguration = null); /// /// Async Operation. /// Join a lobby with lobby ID /// /// Request object for JoinLobbyById /// Configuration for JoinLobbyById /// Task for a Response object containing status code, headers, and Lobby object /// An exception containing the HttpClientResponse with headers, response code, and string of error. Task> JoinLobbyByIdAsync(JoinLobbyByIdRequest request, Configuration operationConfiguration = null); /// /// Async Operation. /// Query public lobbies /// /// Request object for QueryLobbies /// Configuration for QueryLobbies /// Task for a Response object containing status code, headers, and QueryResponse object /// An exception containing the HttpClientResponse with headers, response code, and string of error. Task> QueryLobbiesAsync(QueryLobbiesRequest request, Configuration operationConfiguration = null); /// /// Async Operation. /// Query available lobbies and join a random one /// /// Request object for QuickJoinLobby /// Configuration for QuickJoinLobby /// Task for a Response object containing status code, headers, and Lobby object /// An exception containing the HttpClientResponse with headers, response code, and string of error. Task> QuickJoinLobbyAsync(QuickJoinLobbyRequest request, Configuration operationConfiguration = null); /// /// Async Operation. /// Remove a player /// /// Request object for RemovePlayer /// Configuration for RemovePlayer /// Task for a Response object containing status code, headers /// An exception containing the HttpClientResponse with headers, response code, and string of error. Task RemovePlayerAsync(RemovePlayerRequest request, Configuration operationConfiguration = null); /// /// Async Operation. /// Update lobby data /// /// Request object for UpdateLobby /// Configuration for UpdateLobby /// Task for a Response object containing status code, headers, and Lobby object /// An exception containing the HttpClientResponse with headers, response code, and string of error. Task> UpdateLobbyAsync(UpdateLobbyRequest request, Configuration operationConfiguration = null); /// /// Async Operation. /// Update player data /// /// Request object for UpdatePlayer /// Configuration for UpdatePlayer /// Task for a Response object containing status code, headers, and Lobby object /// An exception containing the HttpClientResponse with headers, response code, and string of error. Task> UpdatePlayerAsync(UpdatePlayerRequest request, Configuration operationConfiguration = null); } /// public class LobbyApiClient : BaseApiClient, ILobbyApiClient { private IAccessToken _accessToken; private const int _baseTimeout = 10; private Configuration _configuration; public Configuration Configuration { get { // We return a merge between the current configuration and the // global configuration to ensure we have the correct // combination of headers and a base path (if it is set). return Configuration.MergeConfigurations(_configuration, LobbyService.Configuration); } } public LobbyApiClient(IHttpClient httpClient, IAccessToken accessToken, Configuration configuration = null) : base(httpClient) { // We don't need to worry about the configuration being null at // this stage, we will check this in the accessor. _configuration = configuration; _accessToken = accessToken; } public async Task> CreateLobbyAsync(CreateLobbyRequest request, Configuration operationConfiguration = null) { var statusCodeToTypeMap = new Dictionary() { { "201", typeof(Models.Lobby) },{ "400", typeof(ErrorStatus) },{ "403", typeof(ErrorStatus) } }; // Merge the operation/request level configuration with the client level configuration. var finalConfiguration = Configuration.MergeConfigurations(operationConfiguration, Configuration); var response = await HttpClient.MakeRequestAsync("POST", request.ConstructUrl(finalConfiguration.BasePath), request.ConstructBody(), request.ConstructHeaders(_accessToken, finalConfiguration), finalConfiguration.RequestTimeout ?? _baseTimeout); var handledResponse = ResponseHandler.HandleAsyncResponse(response, statusCodeToTypeMap); return new Response(response, handledResponse); } public async Task DeleteLobbyAsync(DeleteLobbyRequest request, Configuration operationConfiguration = null) { var statusCodeToTypeMap = new Dictionary() { { "204", null },{ "400", typeof(ErrorStatus) },{ "403", typeof(ErrorStatus) },{ "404", typeof(ErrorStatus) } }; // Merge the operation/request level configuration with the client level configuration. var finalConfiguration = Configuration.MergeConfigurations(operationConfiguration, Configuration); var response = await HttpClient.MakeRequestAsync("DELETE", request.ConstructUrl(finalConfiguration.BasePath), request.ConstructBody(), request.ConstructHeaders(_accessToken, finalConfiguration), finalConfiguration.RequestTimeout ?? _baseTimeout); ResponseHandler.HandleAsyncResponse(response, statusCodeToTypeMap); return new Response(response); } public async Task> GetLobbyAsync(GetLobbyRequest request, Configuration operationConfiguration = null) { var statusCodeToTypeMap = new Dictionary() { { "200", typeof(Models.Lobby) },{ "400", typeof(ErrorStatus) },{ "403", typeof(ErrorStatus) },{ "404", typeof(ErrorStatus) } }; // Merge the operation/request level configuration with the client level configuration. var finalConfiguration = Configuration.MergeConfigurations(operationConfiguration, Configuration); var response = await HttpClient.MakeRequestAsync("GET", request.ConstructUrl(finalConfiguration.BasePath), request.ConstructBody(), request.ConstructHeaders(_accessToken, finalConfiguration), finalConfiguration.RequestTimeout ?? _baseTimeout); var handledResponse = ResponseHandler.HandleAsyncResponse(response, statusCodeToTypeMap); return new Response(response, handledResponse); } public async Task HeartbeatAsync(HeartbeatRequest request, Configuration operationConfiguration = null) { var statusCodeToTypeMap = new Dictionary() { { "204", null },{ "400", typeof(ErrorStatus) },{ "403", typeof(ErrorStatus) },{ "404", typeof(ErrorStatus) } }; // Merge the operation/request level configuration with the client level configuration. var finalConfiguration = Configuration.MergeConfigurations(operationConfiguration, Configuration); var response = await HttpClient.MakeRequestAsync("POST", request.ConstructUrl(finalConfiguration.BasePath), request.ConstructBody(), request.ConstructHeaders(_accessToken, finalConfiguration), finalConfiguration.RequestTimeout ?? _baseTimeout); ResponseHandler.HandleAsyncResponse(response, statusCodeToTypeMap); return new Response(response); } public async Task> JoinLobbyByCodeAsync(JoinLobbyByCodeRequest request, Configuration operationConfiguration = null) { var statusCodeToTypeMap = new Dictionary() { { "200", typeof(Models.Lobby) },{ "400", typeof(ErrorStatus) },{ "403", typeof(ErrorStatus) },{ "409", typeof(ErrorStatus) } }; // Merge the operation/request level configuration with the client level configuration. var finalConfiguration = Configuration.MergeConfigurations(operationConfiguration, Configuration); var response = await HttpClient.MakeRequestAsync("POST", request.ConstructUrl(finalConfiguration.BasePath), request.ConstructBody(), request.ConstructHeaders(_accessToken, finalConfiguration), finalConfiguration.RequestTimeout ?? _baseTimeout); var handledResponse = ResponseHandler.HandleAsyncResponse(response, statusCodeToTypeMap); return new Response(response, handledResponse); } public async Task> JoinLobbyByIdAsync(JoinLobbyByIdRequest request, Configuration operationConfiguration = null) { var statusCodeToTypeMap = new Dictionary() { { "200", typeof(Models.Lobby) },{ "400", typeof(ErrorStatus) },{ "403", typeof(ErrorStatus) },{ "404", typeof(ErrorStatus) },{ "409", typeof(ErrorStatus) } }; // Merge the operation/request level configuration with the client level configuration. var finalConfiguration = Configuration.MergeConfigurations(operationConfiguration, Configuration); var response = await HttpClient.MakeRequestAsync("POST", request.ConstructUrl(finalConfiguration.BasePath), request.ConstructBody(), request.ConstructHeaders(_accessToken, finalConfiguration), finalConfiguration.RequestTimeout ?? _baseTimeout); var handledResponse = ResponseHandler.HandleAsyncResponse(response, statusCodeToTypeMap); return new Response(response, handledResponse); } public async Task> QueryLobbiesAsync(QueryLobbiesRequest request, Configuration operationConfiguration = null) { var statusCodeToTypeMap = new Dictionary() { { "200", typeof(QueryResponse) },{ "400", typeof(ErrorStatus) },{ "403", typeof(ErrorStatus) } }; // Merge the operation/request level configuration with the client level configuration. var finalConfiguration = Configuration.MergeConfigurations(operationConfiguration, Configuration); var response = await HttpClient.MakeRequestAsync("POST", request.ConstructUrl(finalConfiguration.BasePath), request.ConstructBody(), request.ConstructHeaders(_accessToken, finalConfiguration), finalConfiguration.RequestTimeout ?? _baseTimeout); var handledResponse = ResponseHandler.HandleAsyncResponse(response, statusCodeToTypeMap); return new Response(response, handledResponse); } public async Task> QuickJoinLobbyAsync(QuickJoinLobbyRequest request, Configuration operationConfiguration = null) { var statusCodeToTypeMap = new Dictionary() { { "200", typeof(Models.Lobby) },{ "400", typeof(ErrorStatus) },{ "403", typeof(ErrorStatus) },{ "404", typeof(ErrorStatus) },{ "409", typeof(ErrorStatus) } }; // Merge the operation/request level configuration with the client level configuration. var finalConfiguration = Configuration.MergeConfigurations(operationConfiguration, Configuration); var response = await HttpClient.MakeRequestAsync("POST", request.ConstructUrl(finalConfiguration.BasePath), request.ConstructBody(), request.ConstructHeaders(_accessToken, finalConfiguration), finalConfiguration.RequestTimeout ?? _baseTimeout); var handledResponse = ResponseHandler.HandleAsyncResponse(response, statusCodeToTypeMap); return new Response(response, handledResponse); } public async Task RemovePlayerAsync(RemovePlayerRequest request, Configuration operationConfiguration = null) { var statusCodeToTypeMap = new Dictionary() { { "204", null },{ "400", typeof(ErrorStatus) },{ "403", typeof(ErrorStatus) },{ "404", typeof(ErrorStatus) } }; // Merge the operation/request level configuration with the client level configuration. var finalConfiguration = Configuration.MergeConfigurations(operationConfiguration, Configuration); var response = await HttpClient.MakeRequestAsync("DELETE", request.ConstructUrl(finalConfiguration.BasePath), request.ConstructBody(), request.ConstructHeaders(_accessToken, finalConfiguration), finalConfiguration.RequestTimeout ?? _baseTimeout); ResponseHandler.HandleAsyncResponse(response, statusCodeToTypeMap); return new Response(response); } public async Task> UpdateLobbyAsync(UpdateLobbyRequest request, Configuration operationConfiguration = null) { var statusCodeToTypeMap = new Dictionary() { { "200", typeof(Models.Lobby) },{ "400", typeof(ErrorStatus) },{ "403", typeof(ErrorStatus) },{ "404", typeof(ErrorStatus) } }; // Merge the operation/request level configuration with the client level configuration. var finalConfiguration = Configuration.MergeConfigurations(operationConfiguration, Configuration); var response = await HttpClient.MakeRequestAsync("POST", request.ConstructUrl(finalConfiguration.BasePath), request.ConstructBody(), request.ConstructHeaders(_accessToken, finalConfiguration), finalConfiguration.RequestTimeout ?? _baseTimeout); var handledResponse = ResponseHandler.HandleAsyncResponse(response, statusCodeToTypeMap); return new Response(response, handledResponse); } public async Task> UpdatePlayerAsync(UpdatePlayerRequest request, Configuration operationConfiguration = null) { var statusCodeToTypeMap = new Dictionary() { { "200", typeof(Models.Lobby) },{ "400", typeof(ErrorStatus) },{ "403", typeof(ErrorStatus) },{ "404", typeof(ErrorStatus) } }; // Merge the operation/request level configuration with the client level configuration. var finalConfiguration = Configuration.MergeConfigurations(operationConfiguration, Configuration); var response = await HttpClient.MakeRequestAsync("POST", request.ConstructUrl(finalConfiguration.BasePath), request.ConstructBody(), request.ConstructHeaders(_accessToken, finalConfiguration), finalConfiguration.RequestTimeout ?? _baseTimeout); var handledResponse = ResponseHandler.HandleAsyncResponse(response, statusCodeToTypeMap); return new Response(response, handledResponse); } } }