package com.openosrs.client.api.types;

public class Item {
    private final int itemId;
    private final String name;
    private final int quantity;
    private final boolean stackable;
    private final boolean tradeable;
    private final String[] actions;

    public static final Item EMPTY = new Item(-1, "Empty", 0, false, false, new String[0]);

    public Item(int itemId, String name, int quantity, boolean stackable,
               boolean tradeable, String[] actions) {
        this.itemId = itemId;
        this.name = name;
        this.quantity = quantity;
        this.stackable = stackable;
        this.tradeable = tradeable;
        this.actions = actions != null ? actions : new String[0];
    }

    public int getItemId() { return itemId; }
    public String getName() { return name; }
    public int getQuantity() { return quantity; }
    public boolean isStackable() { return stackable; }
    public boolean isTradeable() { return tradeable; }
    public String[] getActions() { return actions.clone(); }

    public boolean isEmpty() {
        return itemId == -1 || quantity == 0;
    }

    public boolean hasAction(String action) {
        for (String a : actions) {
            if (a != null && a.equalsIgnoreCase(action)) {
                return true;
            }
        }
        return false;
    }

    @Override
    public String toString() {
        return isEmpty() ? "Empty" : String.format("Item[%d] %s x%d", itemId, name, quantity);
    }
}
