#pragma once

#include "ClientConnexion.h"
#include "ClientGame.h"

#include "game/Team.h"
#include "game/Player.h"

#include "protocol/Protocol.h"

#include "render/Renderer.h"

#include "network/Network.h"

namespace td {
namespace client {

class Client {
private:
    render::Renderer* m_Renderer;
    ClientConnexion m_Connexion;
    std::unique_ptr<ClientGame> m_Game;
    bool m_Connected;
public:
    Client(render::Renderer* renderer) : m_Renderer(renderer), m_Game(std::make_unique<ClientGame>(this)), m_Connected(false) {}

    const ClientGame& GetGame() const { return *m_Game; }
    const ClientConnexion& GetConnexion() const { return m_Connexion; }
    render::Renderer* GetRenderer() const { return m_Renderer; }

    ClientGame& GetGame() { return *m_Game; }
    ClientConnexion& GetConnexion() { return m_Connexion; }

    void Tick(std::uint64_t delta);

    void Render();

    bool Connect(const network::IPAddresses& addresses, std::uint16_t port);
    void CloseConnection();

    bool IsConnected() const { return m_Connexion.GetSocketStatus() == network::Socket::Connected; }

    void SelectTeam(game::TeamColor team);
    void SendMobs(const std::vector<protocol::MobSend>& mobSends);
    void PlaceTower(game::TowerType type, const glm::vec2& position);
    void UpgradeTower(game::TowerID tower, game::TowerLevel level);
    void RemoveTower(game::TowerID tower);
private:
    void Reset();
};

} // namespace client
} // namespace td
