package org.project.entity.enemies;

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

public abstract class Enemy implements Entity {
    protected boolean isDefending = false;
    private String name;
    private int hp;
    private int mp;

    public Enemy(int hp, int mp, String name) {
        this.hp = hp;
        this.mp = mp;
        this.name = name;
    }

    public void resetDefendState() { this.isDefending = false; }

    @Override
    public void attack(Entity target) {
        System.out.println(GameDisplay.RED + "Enemy attacks! ⚔️" + GameDisplay.RESET);
        target.takeDamage(2);
    }

    @Override
    public void defend() {
        if (getMp() >= 5) {
            this.mp -= 5;
            this.isDefending = true;
            System.out.println(GameDisplay.BLUE + "Enemy defends! 🛡️" + GameDisplay.RESET);
        } else {
            System.out.println(GameDisplay.RED + "Enemy cannot defend! " + GameDisplay.RESET);
        }
    }

    @Override
    public void takeDamage(int damage) {
        if (isDefending) {
            damage = 0;
            this.isDefending = false;
            System.out.println(GameDisplay.GREEN + "Enemy blocks damage! 🛡️" + GameDisplay.RESET);
        }
        else System.out.println(GameDisplay.RED + "Enemy takes " + damage + " damage 🩸" + GameDisplay.RESET);

        this.hp -= damage;
        if (this.hp < 0) this.hp = 0;
    }

    @Override
    public void specialAbility(Entity target) {
        System.out.println(GameDisplay.MAGENTA + "Enemy uses special ability! " + GameDisplay.RESET);
    }

    @Override
    public void heal() {
        if (getMp() >= 6) {
            this.hp += 10;
            if (this.hp > 100) this.hp = 100;
            this.mp -= 6;
            System.out.println(GameDisplay.GREEN + "Enemy heals (+10 HP) 💊" + GameDisplay.RESET);
        } else {
            System.out.println(GameDisplay.RED + "Enemy cannot heal" + GameDisplay.RESET);
        }
    }

    @Override
    public boolean isAlive() { return hp > 0; }

    public String getName() {return name; }

    public int getHp() { return hp; }

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

    public int getMp() { return mp; }

    public void setMp(int newMp) { this.mp = newMp; }
}