// =====================================================================================================================
//  fennec, a free and open source game engine
//  Copyright © 2025  Medusa Slockbower
//
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program.  If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================

#ifndef FENNEC_CORE_EVENT_H
#define FENNEC_CORE_EVENT_H

#include <fennec/lang/types.h>
#include <fennec/lang/typeuuid.h>

namespace fennec
{

struct event;

class event_listener {
public:
	virtual ~event_listener() = default;
	virtual void handle_event(event* event) = 0;
};

struct event {
	const uint64_t type;

	event() = delete;

	template<typename EventT>
	event() : type(typeuuid<EventT>()) { }

	template<typename EventT>
	static void add_listener(event_listener* listener) {
		event::add_listener(listener, typeuuid<EventT, event>());
	}

	template<typename EventT>
	static void dispatch(EventT* event) {
		dispatch(event);
	}

	static void add_listener(event_listener* listener, uint64_t type);
	static void remove_listener(event_listener* listener);
	static void dispatch(event* event);
};

}

#endif // FENNEC_CORE_EVENT_H
