
package org.project.item.armors;
public class Armor {

    public enum ArmorType {
        LIGHT,
        MEDIUM,
        HEAVY
    }


    private String name;
    private ArmorType type;

    private int defense;
    private int maxDefense;

    private int durability;
    private int maxDurability;

    private boolean isBroken;

    // Constructor
    public Armor(String name, ArmorType type, int maxDefense, int maxDurability) {
        this.name = name;
        this.type = type;
        this.maxDefense = maxDefense;
        this.defense = maxDefense;
        this.maxDurability = maxDurability;
        this.durability = maxDurability;
        this.isBroken = false;
    }


    public int reduceDamage(int damage) {

        if (isBroken) {
            return damage;
        }

        int reducedDamage = damage - defense;

        if (reducedDamage < 0) {
            reducedDamage = 0;
        }

        reduceDurability(1);

        return reducedDamage;
    }

    public void reduceDurability(int amount) {
        durability -= amount;

        if (durability <= 0) {
            durability = 0;
            breakArmor();
        }
    }

    // شکستن زره
    private void breakArmor() {
        isBroken = true;
        defense = 0;
    }

    // ===== Getters =====

    public String getName() {
        return name;
    }

    public ArmorType getType() {
        return type;
    }

    public int getDefense() {
        return defense;
    }

    public int getDurability() {
        return durability;
    }

    public int getMaxDurability() {
        return maxDurability;
    }

    public boolean isBroken() {
        return isBroken;
    }

    @Override
    public String toString() {
        return name + " | Type: " + type +
                " | Defense: " + defense +
                " | Durability: " + durability + "/" + maxDurability +
                (isBroken ? " (BROKEN)" : "");
    }
}
