#include "ICharacter.h"
#include <algorithm>

ISkill* ICharacter::getSkill(const std::string& skillName) {
    for (auto& skill : m_skills) {
        if (skill->getName() == skillName) {
            return skill.get();
        }
    }
    return nullptr;
}

bool ICharacter::consumeMana(int amount) {
    if (m_mp >= amount) {
        m_mp -= amount;
        return true;
    }
    return false;
}

void ICharacter::restoreMana(int amount) {
    m_mp += amount;
    if (m_mp > m_maxMp) {
        m_mp = m_maxMp;
    }
}

std::string ICharacter::getStatus() const {
    std::string status = m_name + " (" + m_className + ") ";
    status += "HP: " + std::to_string(m_hp) + "/" + std::to_string(m_maxHp) + " ";
    status += "MP: " + std::to_string(m_mp) + "/" + std::to_string(m_maxMp);
    return status;
}

void ICharacter::addSkill(std::shared_ptr<ISkill> skill) {
    m_skills.push_back(skill);
}
