package org.project.entity.enemies;

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

public abstract class Enemy implements Entity {
    protected String name;
    protected int hp;
    protected int maxHp;
    protected int mp;
    protected int maxMp;
    protected Weapon weapon;
    protected int xpReward = 25;
    protected String keyType;
    protected boolean isStunned = false;

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

    @Override
    public void attack(Entity target) {
        if (isStunned) {
            System.out.println("💫 " + name + " is stunned and cannot move!");
            isStunned = false;
            return;
        }
        int damage = weapon != null ? weapon.getDamage() : 10;
        System.out.println("👹 " + name + " attacks!");
        target.takeDamage(damage);
    }

    @Override
    public void takeDamage(int damage) {
        hp -= damage;
        if (hp < 0) hp = 0;
        System.out.println(name + " took \u001B[31m" + damage + "\u001B[0m damage! (" + hp + "/" + maxHp + " HP remaining)");
    }

    @Override public void defend() {}
    @Override public void heal(int health) { hp += health; if (hp > maxHp) hp = maxHp; }
    @Override public void fillMana(int mana) {}
    @Override public boolean isAlive() { return hp > 0; }

    public void setStunned(boolean stunned) { isStunned = stunned; }
    public String getName() { return name; }
    @Override public int getHp() { return hp; }
    @Override public int getMaxHP() { return maxHp; }
    @Override public int getMp() { return mp; }
    @Override public int getMaxMP() { return maxMp; }
    public Weapon getWeapon() { return weapon; }
    public int getXpReward() { return xpReward; }
    public String getKeyType() { return keyType; }
}