package org.project.entity.enemies;

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

public abstract class Enemy implements Entity {
    Weapon weapon;
    protected int hp;
    protected int maxHP;
    protected boolean defending = false;
    private boolean stunned = false;
    protected boolean revived = false;
    protected boolean alive = true;
    protected boolean key = true;

    public static final String BLUE_TEXT = "\u001B[34m";
    public static final String RESET = "\u001B[0m";

    public Enemy(int hp, Weapon weapon) {
        this.hp = hp;
        maxHP = hp; // TODO: fix this from superclasses
        this.weapon = weapon;
    }

    @Override
    public void takeDamage(int damage) {
        hp -= damage;
        System.out.printf("\t%s took %d damage \uD83D\uDCA5\n", getName(), damage);
    }

    public void attack(Entity target) {
        System.out.printf("\t%s used Light Attack!\n", getName());
        if(target.isDefending()){
            System.out.printf("\t%s is defending. %s lost his attack.\n", target.getName(), getName());
            return;
        }
        target.takeDamage(weapon.getDamage());
    }

    @Override
    public void defend(boolean value) {
        if(value) {
            System.out.printf("\t%s used Defend, You cannot attack in your next turn! \uD83D\uDEE1\uFE0F\n", getName());
            defending = true;
            return;
        }
        defending = false;
    }

    @Override
    public void heal(int health) {
        System.out.printf("\t%s used Heal! ❤\uFE0F\n", getName());
        hp += health;
        if (hp > maxHP) {
            hp = maxHP;
        }
    }

    public void heal(){
        hp = maxHP;
        alive = true;
    }

    public void fillHP(){
        hp = maxHP;
    }

    @Override
    public void stun(boolean value) {
        stunned = value;
    }

    public void dropKey(){
        key = false;
    }

    public int getHp() {
        return hp;
    }

    public int getMaxHP() {
        return maxHP;
    }

    public Weapon getWeapon() {
        return weapon;
    }

    @Override
    public boolean isDefending() {
        return defending;
    }

    public boolean isStunned() {
        return stunned;
    }

    public boolean isRevived() {
        return revived;
    }

    public boolean hasKey() {
        return key;
    }

    @Override
    public boolean isAlive() {
        if(hp <= 0){
            System.out.printf(BLUE_TEXT + "\t=============== You defeated %s =============== " + RESET + "\n\tGoing to the next Location...", getName());

            alive = false;
        }
        return alive;
    }

    public boolean getAlive(){
        if(hp <= 0){
            alive = false;
        }
        return alive;
    }


}
