#include <blitz/godot/NetworkInterface.h>
#include <client/ClientWorld.h>
#include <client/FirstPersonPlayer.h>
#include <client/Main.h>
#include <client/MainMenu.h>
#include <client/Player.h>
#include <server/Server.h>
#include <server/ServerWorld.h>

#include <gdextension_interface.h>
#include <godot_cpp/core/defs.hpp>
#include <godot_cpp/godot.hpp>

using namespace godot;

static void RegisterClasses() {
	GDREGISTER_CLASS(blitz::Player);
	GDREGISTER_CLASS(blitz::FirstPersonPlayer);
	GDREGISTER_CLASS(blitz::MainMenu);
	GDREGISTER_CLASS(blitz::Main);
	GDREGISTER_CLASS(blitz::NetworkInterface);
	GDREGISTER_CLASS(blitz::Server);
	GDREGISTER_ABSTRACT_CLASS(blitz::World);
	GDREGISTER_CLASS(blitz::ClientWorld);
	GDREGISTER_CLASS(blitz::ServerWorld);
}

static void initialize_blitz_module(ModuleInitializationLevel p_level) {
	if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
		return;
	}

	RegisterClasses();
}

static void uninitialize_blitz_module(ModuleInitializationLevel p_level) {
	if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
		return;
	}
}

extern "C" GDExtensionBool GDE_EXPORT library_init(GDExtensionInterfaceGetProcAddress p_get_proc,
	const GDExtensionClassLibraryPtr p_library, GDExtensionInitialization* r_initialization) {
	godot::GDExtensionBinding::InitObject init_obj(p_get_proc, p_library, r_initialization);

	init_obj.register_initializer(initialize_blitz_module);
	init_obj.register_terminator(uninitialize_blitz_module);
	init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SCENE);

	return init_obj.init();
}
