#ifndef DRONE_HPP
#define DRONE_HPP

#include "car_player.hpp"
#include "godot_cpp/classes/animation_player.hpp"
#include "godot_cpp/classes/navigation_agent3d.hpp"
#include "godot_cpp/classes/packed_scene.hpp"
#include <godot_cpp/classes/node3d.hpp>

namespace godot {
enum class DroneState {
    CHASE, DROP, FLEE
};
class Drone : public Node3D {
    GDCLASS(Drone, Node3D);
    static void _bind_methods();
public:
    virtual void _ready() override;
    virtual void _process(double delta_time) override;
    void process_chase(double delta_time);
    void process_flee(double delta_time);
    void process_navigate(double delta_time);
    void recalculate_navigation();
    void spawn_explosion();
    void key_found(int total);

    void start_flee();
    void end_flee();

    void set_explosion_scene(Ref<PackedScene> scene);
    Ref<PackedScene> get_explosion_scene() const;
private:
    int recalc_frame_interval{10};
    int next_recalc{10};
    float speed{30.f};
    float lead_time{2.f};
    float target_distance{3.f};
    DroneState state{DroneState::CHASE};
    CarPlayer *player{nullptr};
    Ref<PackedScene> explosion_scene{};

    NavigationAgent3D *agent{nullptr};
    AnimationPlayer *anim{nullptr};
};
}

#endif // !DRONE_HPP
