#include "register_types.h"
#include "goap/state.hpp"
#include "rts_actions.hpp"
#include "rts_game_mode.hpp"
#include "rts_player.hpp"
#include "rts_states.hpp"
#include "unit.hpp"
#include "unit_world_state.hpp"
#include "goap/action.hpp"
#include "goap/action_db.hpp"
#include "goap/actor_world_state.hpp"
#include "goap/goal.hpp"
#include "goap/planner.hpp"
#include "utils/register_types.hpp"
#include <gdextension_interface.h>
#include <godot_cpp/core/class_db.hpp>
#include <godot_cpp/core/defs.hpp>
#include <godot_cpp/godot.hpp>

using namespace godot;

void initialize_gdextension_types(ModuleInitializationLevel p_level)
{
    if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
        return;
    }
    utils::godot_cpp_utils_register_types();

    // always register actions before classes,
    // so that ActionDB::get_enum_hint is complete before _bind_methods
    goap::ActionDB::register_action<MoveToTarget>();
    goap::ActionDB::register_action<FireAtTarget>();
    goap::ActionDB::register_action<FindTarget>();

    ClassDB::register_class<goap::ActorWorldState>();
    ClassDB::register_class<goap::Goal>();
    ClassDB::register_class<goap::Planner>();
    ClassDB::register_class<goap::State>();

    ClassDB::register_class<MoveTo>();
    ClassDB::register_class<Animate>();
    ClassDB::register_class<Activate>();

    ClassDB::register_class<UnitWorldState>();
    ClassDB::register_class<GoalMarker>();
    ClassDB::register_class<Unit>();
    ClassDB::register_class<RTSGameMode>();
    ClassDB::register_class<RTSPlayer>();
}

extern "C"
{
    // Initialization
    GDExtensionBool GDE_EXPORT metro_rts_library_init(GDExtensionInterfaceGetProcAddress p_get_proc_address, GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization)
    {
        GDExtensionBinding::InitObject init_obj(p_get_proc_address, p_library, r_initialization);
        init_obj.register_initializer(initialize_gdextension_types);
        init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SCENE);

        return init_obj.init();
    }
}
