#ifndef _H_AI_H
#define _H_AI_H

#include <memory>
#include <thread>
#include <mutex>
#include <string>
#include <sol/sol.hpp>

class GameActor;
class Raycaster;
class AIScript;

enum class AIState {
	Idle,
	Alert,
	Patrol
};

class AI {
public:
	AI(GameActor* actor, std::unique_ptr<Raycaster> raycaster);
	void update();

	void setTarget(GameActor* target) { this->target = target; }
	void attachBehaviourScript(std::unique_ptr<AIScript> behaviour);

	AIState getState() const { return state; }
	void setState(AIState state) { this->state = state; }

	~AI();

private:
	AIState						state;
	std::unique_ptr<Raycaster>	raycaster;
	std::unique_ptr<AIScript>		behaviour;
	GameActor*	actor;
	GameActor*	target;

	// cache our lua function calls
	sol::function				idleFunc;
	sol::function				patrolFunc;
	sol::function				alertFunc;

	std::chrono::high_resolution_clock::time_point lastGCTime;
	std::chrono::minutes GCTimeout;
};

#endif
