package org.project.item.armors;

// TODO: UPDATE IMPLEMENTATION
public abstract class Armor{
//    private int defense;
//    private final int maxDefense;
    private int defensePercentage;
    private int maxPercentage;
    private int durability;
    private int maxDurability;


    private boolean isBroke;

    public Armor(int maxPercentage, int maxDurability) {
//        this.maxDefense = maxDefense;
//        this.defense = maxDefense;
        this.maxPercentage = maxPercentage;
        this.defensePercentage = maxPercentage;
        this.maxDurability = maxDurability;
        this.durability = maxDurability;
    }


    public void setMaxDurability(int maxDurability)
    {
        this.maxDurability = maxDurability;
    }

    public int getMaxDurability() {
        return maxDurability;
    }



    public void checkBreak() {
        if (durability <= 0) {
            isBroke = true;
            defensePercentage = 0;
            System.out.println("Your armor broke!");
        }
    }

    // TODO: (BONUS) UPDATE THE REPAIR METHOD
    public void repair() {
        isBroke = false;
        defensePercentage = maxPercentage;
        durability = maxDurability;
    }

    public int getDefense(int damage) {
        int defense = (defensePercentage * damage) / 100;
        this.defensePercentage -= (10 * this.defensePercentage) / 100;
        reduceDurability(15);
        return defense;

    }

    public int getDurability() {
        return durability;
    }

    public boolean isBroke() {
        return isBroke;
    }

    public void setBroke(boolean broke) {
        isBroke = broke;
    }

    public void setDurability(int durability) {
        this.durability = durability;
    }

    public void reduceDurability(int percentage)
    {
        if(durability < percentage)
        {
            this.durability = 0;
        }
        else {
            this.durability -= (percentage * this.durability) / 100;
        }
    }

    public void setMaxPercentage(int maxPercentage) {
        this.maxPercentage = maxPercentage;
    }

    public int getMaxPercentage() {
        return maxPercentage;
    }

    public int getDefensePercentage() {
        return defensePercentage;
    }
}
