#pragma once

#include "td/protocol/Protocol.h"
#include "td/game/BaseGame.h"

namespace td {
namespace protocol {

struct WorldData {
	std::unordered_map<game::ChunkCoord, game::ChunkPtr> m_Chunks;
};

class WorldDataPacket : public Packet {
private:
	WorldData m_WorldData;

	const game::World* m_World;
public:
	WorldDataPacket() {}
	WorldDataPacket(const game::World* world) : m_World(world) {}
	virtual ~WorldDataPacket() {}

	virtual DataBuffer Serialize(bool packetID = true) const;
	virtual void Deserialize(DataBuffer& data);
	virtual void Dispatch(PacketHandler* handler) const;

	virtual PacketType GetType() const { return PacketType::WorldData; }

	const std::unordered_map<game::ChunkCoord, game::ChunkPtr>& GetChunks() const { return m_WorldData.m_Chunks; }

	DataBuffer SerializeCustom() const; // allow serialisation with invalid World member
	void SetWorldData(const WorldData& worldData) { m_WorldData = worldData; }
};

} // namespace protocol
} // namespace td
