#ifndef EDITSCENE_CHARACTER_CLASS_COMPONENT_HPP
#define EDITSCENE_CHARACTER_CLASS_COMPONENT_HPP
#pragma once

#include <Ogre.h>
#include <unordered_map>

/**
 * Runtime character progression state.
 *
 * Stores the character's current level, XP, available points,
 * and current stat/skill/need values.
 *
 * The class template (base stats, formulas, growth curves) lives in
 * the CharacterClassDatabase singleton. This component only holds
 * the mutable runtime state for a specific entity.
 */
struct CharacterClassComponent {
	/** Class name referencing CharacterClassDatabase */
	Ogre::String className;

	/** Current level (starts at 1, no cap) */
	int level = 1;

	/** Accumulated experience points */
	int64_t currentXP = 0;

	/** Unspent stat points from level ups */
	int availablePoints = 0;

	/** Current stat values (e.g., strength, dexterity, hp_max) */
	std::unordered_map<Ogre::String, int> stats;

	/** Current pool values (e.g., hp_current, stamina_current).
	 *  For ResourcePool stats, stats["hp"] is the maximum
	 *  and currentPools["hp"] is the current value. */
	std::unordered_map<Ogre::String, int> currentPools;

	/** Current skill values (0-100 proficiency) */
	std::unordered_map<Ogre::String, int> skills;

	/** Current need values (0-1000) */
	std::unordered_map<Ogre::String, int> needs;

	/** True if the entity has a pending level up (waiting for player) */
	bool levelUpPending = false;

	/** True if the character sheet is open (player only) */
	bool sheetOpen = false;

	/**
	 * Get a stat value.
	 * For Attribute: returns the stat value clamped to min/max.
	 * For ResourcePool: returns the CURRENT pool value.
	 * Returns 0 if the stat does not exist.
	 */
	int getStat(const Ogre::String &name) const;

	/**
	 * Get the maximum value of a resource pool.
	 * Returns 0 if the stat is not a ResourcePool or does not exist.
	 */
	int getPoolMax(const Ogre::String &name) const;

	/**
	 * Get the current value of a resource pool.
	 * Returns 0 if the stat is not a ResourcePool or does not exist.
	 */
	int getPoolCurrent(const Ogre::String &name) const;

	/**
	 * Set the current value of a resource pool.
	 * Value is clamped to [0, max].
	 */
	void setPoolCurrent(const Ogre::String &name, int value);

	/**
	 * Get a skill value, clamped to 0-100.
	 * Returns 0 if the skill does not exist.
	 */
	int getSkill(const Ogre::String &name) const;

	/**
	 * Get a need value, clamped to 0-1000.
	 * Returns 0 if the need does not exist.
	 */
	int getNeed(const Ogre::String &name) const;
};

/**
 * Per-entity overrides to class defaults.
 *
 * Applied on top of the class base values during character creation
 * or whenever stats are recomputed.
 */
struct CharacterClassOverrideComponent {
	/** Flat offsets added to base stats */
	std::unordered_map<Ogre::String, int> statOffsets;

	/** Flat offsets added to base skills */
	std::unordered_map<Ogre::String, int> skillOffsets;

	/** Flat offsets added to base needs */
	std::unordered_map<Ogre::String, int> needOffsets;
};

#endif // EDITSCENE_CHARACTER_CLASS_COMPONENT_HPP
