/**
 * Copyright (c) 2025 Dominic Masters
 * 
 * This software is released under the MIT License.
 * https://opensource.org/licenses/MIT
 */

#pragma once
#include "client/networked/networkedclient.h"
#include "packet/packetqueue.h"

typedef enum {
  CLIENT_TYPE_NETWORKED,
  CLIENT_TYPE_SINGLE_PLAYER,
} clienttype_t;

typedef enum {
  CLIENT_STATE_DISCONNECTED,
  CLIENT_STATE_CONNECTING,
  CLIENT_STATE_CONNECTED,
  CLIENT_STATE_DISCONNECTING,
} clientstate_t;

typedef struct clientconnect_s {
  clienttype_t type;
  union {
    networkedclientconnect_t networked;
  };
} clientconnect_t;

typedef struct client_s {
  clientstate_t state;
  clienttype_t type;
  packetqueue_t packetQueue;

  union {
    networkedclient_t networked;
  };
} client_t;

extern client_t CLIENT;

/**
 * Initializes the client.
 * 
 * @return Error code indicating success or failure.
 */
void clientInit();

/**
 * Connects to a server.
 * 
 * @param connect Connection information.
 * @return Error code indicating success or failure.
 */
errorret_t clientConnect(const clientconnect_t connect);

/**
 * Disconnects the client from the server.
 */
void clientDisconnect();

/**
 * Cleans up the client resources.
 */
void clientDispose();