package org.project.item.armors;

import org.project.entity.Entity;
import org.project.item.Item;

public abstract class Armor implements Item {
    private int defense;
    private int maxDefense;
    private int durability;
    private int maxDurability;
    public boolean isBroke;

    public Armor(int defense, int durability) {
        this.defense = defense;
        this.durability = durability;
        this.maxDefense = defense;
        this.maxDurability = durability;
        this.isBroke = false;
    }

    public boolean checkBreak() {
        if (durability <= 0) {
            isBroke = true;
            defense = 0;
            durability = 0;
            System.out.println("Armor is broken!");
        }
        return isBroke;
    }

    public void repair() {
        if (isBroke) {
            isBroke = false;
            defense = maxDefense;
            durability = maxDurability;
            System.out.println("🔧 Armor repaired! Defense: " + defense + ", Durability: " + durability);
        }
        else {
            System.out.println("Armor is not broken. No need to repair.");
        }
    }

    public void reduceDurability(int amount) {
        if (!isBroke) {
            durability -= amount;
            checkBreak();
        }
    }

    @Override
    public void use(Entity target) {
        System.out.println("🛡️ " + getClass().getSimpleName() + " equipped. Defense: " + defense);
    }

    public int getDefense() {
        return defense;
    }

    public int getDurability() {
        return durability;
    }

    public boolean isBroke() {
        return isBroke;
    }

    public void setDefense(int defense) {
        this.defense = defense;
    }
}
