#ifndef EDITSCENE_PATH_FOLLOWING_HPP
#define EDITSCENE_PATH_FOLLOWING_HPP
#pragma once

#include <Ogre.h>
#include <vector>
#include <string>
#include <utility>

/**
 * Animation state configuration for path following.
 *
 * Each state (e.g. "idle", "walk", "run") consists of unlimited
 * state-machine-name -> state-name pairs applied via AnimationTreeSystem.
 */
struct PathFollowingState {
	Ogre::String name;
	std::vector<std::pair<Ogre::String, Ogre::String> > stateMachineStates;

	PathFollowingState() = default;
	explicit PathFollowingState(const Ogre::String &name_)
		: name(name_)
	{
	}
};

/**
 * Path Following component.
 *
 * Configures animation states for locomotion (idle/walk/run)
 * and stores the current locomotion state. Used by GoapRunner
 * to animate characters during plan execution.
 */
struct PathFollowingComponent {
	// Animation state configurations
	std::vector<PathFollowingState> pathFollowingStates = {
		PathFollowingState("idle"),
		PathFollowingState("walk"),
		PathFollowingState("run"),
	};

	// Current locomotion state name
	Ogre::String currentLocomotionState = "idle";

	// Walk speed (m/s) for root motion scaling
	float walkSpeed = 2.5f;

	// Run speed (m/s) for root motion scaling
	float runSpeed = 5.0f;

	// Whether to use root motion
	bool useRootMotion = true;

	// Target position for path following (set by GoapRunner)
	Ogre::Vector3 targetPosition = Ogre::Vector3::ZERO;

	// Whether we have an active target
	bool hasTarget = false;

	// Path waypoints (set by GoapRunner, followed by PathFollowingSystem)
	std::vector<Ogre::Vector3> path;
	int pathIndex = 0;
	float pathRecalcTimer = 0.0f;

	PathFollowingComponent() = default;

	const PathFollowingState *findState(const Ogre::String &name) const
	{
		for (const auto &state : pathFollowingStates) {
			if (state.name == name)
				return &state;
		}
		return nullptr;
	}
};

#endif // EDITSCENE_PATH_FOLLOWING_HPP
