package org.project.entity.enemies;

import org.project.entity.Entity;
import org.project.item.armors.Armor;
import org.project.item.weapons.Weapon;

public abstract class Enemy implements Entity{
    Weapon weapon;
    private int hp;
    private int mp;
    private int maxHp;
    private boolean isAlive = true;
    private int maxMp;

    private int xpReward;
    private boolean hasDroppedKey = false;
    private boolean keyDroppable = false;
    private boolean isStunned = false;

    public static final String GREEN = "\u001B[32m";
    public static final String RESET = "\u001B[0m";



    public Enemy(int hp, int mp, Weapon weapon) {
        this.hp = hp;
        this.mp = mp;
        this.weapon = weapon;
        this.maxHp = maxHp;
    }

    @Override
    public void takeDamage(int damage) {
        if (!isAlive) return;
        hp -= damage;

        System.out.println("❤️ " + this.getClass().getSimpleName() + " HP remaining: " + hp + "/" + maxHp);

        if (this.hp <= 0) {
            this.hp = 0;
            this.isAlive = false;
        }
    }

    @Override
    public void defend()
    {
        System.out.println(this.getClass().getSimpleName() + " attempts to defend!");
    }

    @Override
    public void heal(int health)
    {
        if (!isAlive) return;
        this.hp += health;
        if (this.hp > maxHp) this.hp = maxHp;
        System.out.println("💚 " + this.getClass().getSimpleName() + " healed " + health + " HP!");
    }

    @Override
    public boolean isAlive() {
        return this.isAlive;
    }

    public abstract void attack(Entity target);

    public int getHp() {
        return hp;
    }

    public void setHp(int hp)
    {
        this.hp = hp;
    }

    public int getMp() {
        return mp;
    }

    public Weapon getWeapon() {
        return weapon;
    }

    public void setStunned(boolean b)
    {
        this.isStunned = b;
    }

    public int getXpReward()
    {
        return xpReward;
    }

    public boolean hasKey()
    {
        return keyDroppable && !hasDroppedKey;
    }

    public void dropKey()
    {
        if (keyDroppable && !hasDroppedKey)
        {
            hasDroppedKey = true;
            System.out.println("🔑 " +GREEN+ this.getClass().getSimpleName() + " dropped a key!"+RESET);
        }
    }

    public void setKeyDroppable(boolean droppable)
    {
        this.keyDroppable = droppable;
    }

    public void setXpReward(int xp)
    {
        this.xpReward = xp;
    }

    @Override
    public void fillMana(int mana)
    {
        this.mp = 0;
    }

    public int getMaxHP() {
        return maxHp;
    }

    public int getMaxMP() {
        return maxHp;
    }
}
