#ifndef RTS_UNIT_HPP
#define RTS_UNIT_HPP

#include "goal_marker.hpp"
#include "unit_world_state.hpp"
#include "goap/goal.hpp"
#include "goap/planner.hpp"
#include <godot_cpp/classes/character_body3d.hpp>
#include <godot_cpp/classes/navigation_agent3d.hpp>
#include <godot_cpp/classes/node3d.hpp>
#include <godot_cpp/variant/callable.hpp>

namespace gd = godot;


class Unit : public gd::CharacterBody3D {
    GDCLASS(Unit, gd::CharacterBody3D);
    static void _bind_methods();
public:
    virtual void _enter_tree() override;
    virtual void _process(double delta_time) override;

    void stop_plan();
    void plan_for_marker(GoalMarker *marker);
    void plan_for_goal(gd::Ref<goap::Goal> goal);
    UnitWorldState *get_world_state() const;
private:
    void destroy_state();
    void next_action();
private:
    goap::Plan current_plan{};
    goap::State *state{nullptr};

    gd::Node3D *eyes{nullptr};

    gd::Callable on_end_state{callable_mp(this, &Unit::next_action)};

    gd::NavigationAgent3D *agent{nullptr};
    UnitWorldState *world_state{nullptr};
    goap::Planner *planner{nullptr};
};

#endif // !RTS_UNIT_HPP
