#pragma once

#include "td/game/BaseGame.h"

#include "td/protocol/PacketHandler.h"

#include "WorldClient.h"

#include "client/render/WorldRenderer.h"
#include "client/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& GetWorldClient() { return m_WorldClient; }

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

};

} // namespace client
} // namespace td
