#ifndef ENEMY_WRETCHED_H
#define ENEMY_WRETCHED_H

#include "wave_survival/enemy_body.h"
#include "wave_survival/state.h"
class PatrolPath;
class NpcUnit;
class AnimationPlayer;
class StateMachine;

class EnemyWretched : public EnemyBody {
	GDCLASS(EnemyWretched, EnemyBody);
	static void _bind_methods();
	void on_child_entered(Node *node);
	void ready();

protected:
	void _notification(int what);

public:
	void set_chase_speed(float speed);
	float get_chase_speed() const;
	AnimationPlayer *get_anim() const;

private:
	float chase_speed{ 5.f };
	StateMachine *fsm{ nullptr };
	AnimationPlayer *anim{ nullptr };
};

/* ============================== STATES ============================== */

class WretchedState : public State {
	GDCLASS(WretchedState, State);
	static void _bind_methods() {}

public:
	virtual void set_target(Node *node) override;
	EnemyWretched *get_target() const;
	NpcUnit *get_unit() const;
	NavigationAgent3D *get_nav() const;
	AnimationPlayer *get_anim() const;

private:
	EnemyWretched *target{ nullptr };
};

class WretchedPatrolState : public WretchedState {
	GDCLASS(WretchedPatrolState, WretchedState);
	static void _bind_methods() {}
	void set_patrol_target(Vector3 path_point);
	void on_velocity_calculated(Vector3 direction);

public:
	virtual void enter_state() override;
	virtual void process(double delta) override;
	virtual String get_next_state() const override;
	virtual void exit_state() override;

private:
	int path_point{ 0 };
	PatrolPath *path{ nullptr };
	Callable mp_on_velocity_calculated{ callable_mp(this, &self_type::on_velocity_calculated) };
};

class WretchedChaseState : public WretchedState {
	GDCLASS(WretchedChaseState, WretchedState);
	static void _bind_methods() {}

public:
	virtual void enter_state() override;
	virtual void process(double delta) override;
	virtual String get_next_state() const override;
};

class WretchedAttackState : public WretchedState {
	GDCLASS(WretchedAttackState, WretchedState);
	static void _bind_methods() {}

public:
	virtual void enter_state() override;
	virtual String get_next_state() const override;
};

#endif // !ENEMY_WRETCHED_H
