package org.project.item.consumables;

import org.project.entity.Entity;
import org.project.location.NarrativeConsole;

public class Flask extends Consumable {
    public Flask(String name, int healingPercent) {
        super(name , healingPercent);
    }

    @Override
    public void use(Entity target) {
        //Checking if the target is alive
        if (target == null || target.getHp() <= 0) {
            NarrativeConsole.printWarning("❌ Target is dead already!");
            return;
        }

        int healAmount = target.getMaxHP() * healingPercent / 100;
        if (healAmount < 10) {
            healAmount = 10;
        }

        int oldHp = target.getHp();
        target.heal(healAmount);
        int actualHeal = target.getHp() - oldHp;

        NarrativeConsole.printHeal("🧪🧪🧪 ============== 🧪🧪🧪");
        NarrativeConsole.printHeal("💚 " + getName() + " drinks the Healing Flask!");
        NarrativeConsole.printHeal("✨ Restored " + actualHeal + " HP!");
        NarrativeConsole.printHeal("💚 HP: " + target.getHp() + "/" + target.getMaxHP());

        if (target.getHp() == target.getMaxHP()) {
            NarrativeConsole.printHeal("💪 " + getName() + " is fully healed!");
        }
        NarrativeConsole.printHeal("🧪🧪🧪 ============== 🧪🧪🧪");
    }
}