#ifndef EVENT_MANAGER_H
#define EVENT_MANAGER_H

#include <map>
#include <memory>
#include <mutex>
#include <vector>

#include "Event.h"

class EventHandlerBase;

class EventManager
{
public:
	static std::shared_ptr<EventManager> getInstance();
	static void destroyInstance();

private:
	static std::shared_ptr<EventManager> s_instance;

public:
	EventManager(EventManager const &) = delete;
	void operator=(EventManager const &) = delete;

	void registerEventHandler(EventHandlerBase *eventHandler);
	void unregisterEventHandler(EventHandlerBase *eventHandler);
	void sendEventImmediately(std::shared_ptr<Event> event);
	void addEvent(std::shared_ptr<Event> event);
	void processEvents();
	void clearEvents();

	bool hasEvents() const;

private:
	EventManager() = default;

	std::map<unsigned int, EventHandlerBase *> m_eventHandlers;
	std::vector<std::shared_ptr<Event>> m_events;
	std::mutex m_eventHandlersMutex;
	std::mutex m_eventsMutex;
};

#endif   // EVENT_MANAGER_H
