package org.project.item.weapons;

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

// TODO: UPDATE IMPLEMENTATION
public abstract class Weapon implements Item {
    private int damage;
    private int manaCost;

    /*
    TODO: ADD OTHER REQUIRED AND BONUS ATTRIBUTES
    */
    /*
    Added shared item attributes for inspection and inventory usage.
    Subclasses will define the concrete values (name, description, value).
    */
    private String name;
    private String description;
    private int value;

    /*
    Added durability system so weapons can degrade through combat usage.
    */
    private int durability = 100;
    private int maxDurability = 100;

    public Weapon(int damage, int manaCost) {
        this.damage = damage;
        this.manaCost = manaCost;
    }

    @Override
    public void use(Entity target) {
        target.takeDamage(damage);
        reduceDurability();
    }

    public int getDamage() {
        return damage;
    }

    public int getManaCost() {
        return manaCost;
    }
    /*
    Reduces durability whenever the weapon is used.
    */
    private void reduceDurability() {
        durability--;
        if (durability < 0) {
            durability = 0;
        }
    }

    /*
    TODO: ADD OTHER REQUIRED AND BONUS METHODS
    */
    /*
    Repair weapon durability.
    */
    public void repair() {
        durability = maxDurability;
    }

    /*
    Implemented inspection methods required by Item interface.
    */
    @Override
    public String getName() {
        return name;
    }

    @Override
    public String getDescription() {
        return description;
    }

    @Override
    public int getValue() {
        return value;
    }

    /*
    Durability getters.
    */
    public int getDurability() {
        return durability;
    }

    public int getMaxDurability() {
        return maxDurability;
    }
}
