package org.project.item.weapons;

import org.project.entity.Entity;
import java.util.ArrayList;
import java.io.Serializable;

public abstract class Weapon implements Serializable
{

    private static final long serialVersionUID = 1L;

    protected String name;
    protected int damage;
    protected int manaCost;
    protected int level;
    protected int durability;
    protected boolean isBroken;

    public Weapon(String name, int damage, int manaCost)
    {
        this.name = name;
        this.damage = damage;
        this.manaCost = manaCost;
        this.level = 1;
        this.durability = 100;
        this.isBroken = false;
    }

    public void use(Entity target)
    {
        if (isBroken)
        {
            System.out.println("⚠️ " + name + " is broken and can't be used!");
            return;
        }

        target.takeDamage(damage);
        reduceDurability(1);
    }

    public abstract void uniqueAbility(ArrayList<Entity> targets);

    protected void reduceDurability(int amount)
    {
        durability = Math.max(0, durability - amount);
        if (durability == 0)
        {
            isBroken = true;
        }
    }

    public void upgrade()
    {
        level++;
        damage += 5;
        System.out.println("🛠️ " + name + " upgraded to level " + level + "!");
    }

    public String getName() {
        return name;
    }

    public int getDamage()
    {
        return damage;
    }

    public int getManaCost()
    {
        return manaCost;
    }

    public int getLevel()
    {
        return level;
    }

    public int getDurability()
    {
        return durability;
    }

    public boolean isBroken()
    {
        return isBroken;
    }
}