#include "blitz/protocol/PacketFactory.h"

#include "blitz/protocol/Packets.h"
#include <array>
#include <functional>
#include <map>
#include <memory>

namespace blitz {
namespace protocol {
namespace PacketFactory {

typedef std::unique_ptr<Packet> PacketPtr;

static std::array<PacketPtr, static_cast<std::size_t>(PacketType::PACKET_COUNT)> Packets = {
	std::make_unique<PlayerLoginPacket>(),
	std::make_unique<UpdateHealthPacket>(),
	std::make_unique<ConnexionInfoPacket>(),
	std::make_unique<PlayerJoinPacket>(),
	std::make_unique<PlayerLeavePacket>(),
	std::make_unique<PlayerListPacket>(),
	std::make_unique<PlayerStatsPacket>(),
	std::make_unique<ServerConfigPacket>(),
	std::make_unique<ServerTpsPacket>(),
	std::make_unique<UpdateGameStatePacket>(),
	std::make_unique<KeepAlivePacket>(),
	std::make_unique<DisconnectPacket>(),
	std::make_unique<ChatPacket>(),
	std::make_unique<PlayerPositionAndRotationPacket>(),
	std::make_unique<PlayerShootPacket>(),
};

const Packet* CreatePacket(PacketType type, DataBuffer& buffer) {
	PacketPtr& packet = Packets[static_cast<std::size_t>(type)];
	packet->Deserialize(buffer);
	return packet.get();
}

}  // namespace PacketFactory
}  // namespace protocol
}  // namespace blitz
