package org.project.item.armors;

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

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

    public void takeHit(int damageToDurability)
    {
        if (!isBroke)
        {
            durability -= damageToDurability;
            if (durability < 0) durability = 0;
            checkBreak();
        }
    }

    public void checkBreak()
    {
        if (durability <= 0)
        {
            isBroke = true;
            defense = 0;
        }
        else
        {
            isBroke = false;
            defense = maxDefense;
        }
    }

    public void repair()
    {
        if (isBroke)
        {
            isBroke = false;
            defense = maxDefense;
            durability = maxDurability;
            System.out.println("Armor repaired successfully!");
        }
        else
        {
            System.out.println("Armor is still intact. No repair needed.");
        }
    }

    public int getDefense() {return defense;}

    public int getDurability() {return durability;}

    public boolean isBroke() {return isBroke;}

    public int getMaxDefense() {return maxDefense;}

    public int getMaxDurability() {return maxDurability;}
}
