#pragma once

/**
 * \file PacketDispatcher.h
 * \brief File containing the blitz::protocol::PacketDispatcher class
 */

#include <blitz/common/NonCopyable.h>
#include <blitz/protocol/Packets.h>

#include <map>

namespace blitz {
namespace protocol {

class PacketHandler;

/**
 * \class PacketDispatcher
 * \brief Class used to dispatch packets
 */
class PacketDispatcher : private NonCopyable {
  private:
	std::map<PacketType, std::vector<PacketHandler*>> m_Handlers;

  public:
	/**
	 * \brief Constructor
	 */
	PacketDispatcher() {}

	/**
	 * \brief Dispatch a packet
	 * \param packet The packet to dispatch
	 */
	void Dispatch(const Packet& packet);

	/**
	 * \brief Register a packet handler
	 * \param type The packet type
	 * \param handler The packet handler
	 */
	void RegisterHandler(PacketType type, PacketHandler& handler);
	/**
	 * \brief Unregister a packet handler
	 * \param type The packet type
	 * \param handler The packet handler
	 */
	void UnregisterHandler(PacketType type, PacketHandler& handler);
	/**
	 * \brief Unregister a packet handler
	 * \param handler The packet handler
	 */
	void UnregisterHandler(PacketHandler& handler);
};

}  // namespace protocol
}  // namespace blitz
