#pragma once

#include "game/BaseGame.h"

#include "protocol/PacketHandler.h"

#include "WorldClient.h"

#include "render/WorldRenderer.h"
#include "render/Renderer.h"

namespace td {
namespace client {

class Client;

class ClientGame : public protocol::PacketHandler, public game::Game {
private:
    Client* m_Client;
    std::uint8_t m_ConnexionID;
    std::uint32_t m_LobbyTime = 0;
    game::Player* m_Player = nullptr;
    render::Renderer* m_Renderer;
    client::WorldClient m_WorldClient;
    render::WorldRenderer m_WorldRenderer;
public:
    ClientGame(Client* client);
    virtual ~ClientGame();

    virtual void tick(std::uint64_t delta);

    void renderWorld();

    std::uint32_t getLobbyTime() const { return m_LobbyTime; }
    const game::Player* getPlayer() const { return m_Player; }
    const WorldClient& getWorld() const { return m_WorldClient; }
    Client* getClient() const { return m_Client; }

    render::Renderer* getRenderer() const { return m_Renderer; }
    WorldClient& getWorld() { return m_WorldClient; }

    virtual void HandlePacket(const protocol::ConnexionInfoPacket* packet);
    virtual void HandlePacket(const protocol::PlayerJoinPacket* packet);
    virtual void HandlePacket(const protocol::PlayerLeavePacket* packet);
    virtual void HandlePacket(const protocol::PlayerListPacket* packet);
    virtual void HandlePacket(const protocol::UpdatePlayerTeamPacket* packet);
    virtual void HandlePacket(const protocol::UpdateGameStatePacket* packet);
    virtual void HandlePacket(const protocol::UpdateLobbyTimePacket* packet);
    virtual void HandlePacket(const protocol::UpdateMoneyPacket* packet);
    virtual void HandlePacket(const protocol::DisconnectPacket* packet);
    virtual void HandlePacket(const protocol::WorldDataPacket* packet);

};

} // namespace client
} // namespace td
