#ifndef EDITSCENE_PATH_FOLLOWING_SYSTEM_HPP
#define EDITSCENE_PATH_FOLLOWING_SYSTEM_HPP
#pragma once

#include <flecs.h>
#include <Ogre.h>

// Forward declarations
class AnimationTreeSystem;
class NavMeshSystem;

/**
 * System that follows navmesh paths and drives character movement.
 *
 * Reads path waypoints from PathFollowingComponent, advances waypoints,
 * rotates the character toward the movement direction (Y-axis only),
 * sets linear velocity for root motion, and applies animation states
 * via AnimationTreeSystem.
 */
class PathFollowingSystem {
public:
	PathFollowingSystem(flecs::world &world, Ogre::SceneManager *sceneMgr,
			    NavMeshSystem *navSystem);
	~PathFollowingSystem();

	void setAnimationTreeSystem(AnimationTreeSystem *system)
	{
		m_animTreeSystem = system;
	}

	void update(float deltaTime);

private:
	void applyLocomotionState(flecs::entity e);
	Ogre::Vector3 getEntityPosition(flecs::entity e);
	void rotateTowards(flecs::entity e, const Ogre::Vector3 &direction,
			   float deltaTime);

	flecs::world &m_world;
	Ogre::SceneManager *m_sceneMgr;
	NavMeshSystem *m_navSystem;
	AnimationTreeSystem *m_animTreeSystem = nullptr;
};

#endif // EDITSCENE_PATH_FOLLOWING_SYSTEM_HPP
