package cz.jzitnik.game.entities.items;

import cz.jzitnik.game.entities.Block;
import cz.jzitnik.game.SpriteLoader;
import cz.jzitnik.game.entities.MyOptional;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
public class Item {
    private String id;
    private String name;
    private ItemType type;
    private MyOptional<ToolVariant> toolVariant = MyOptional.empty();
    private SpriteLoader.SPRITES sprite;
    private MyOptional<Enum> spriteState = MyOptional.empty();
    private boolean stackable = true;
    private int durability;
    private int maxDurability;
    private double miningDecrease = 0;
    private int stackAmount = 64;
    private int addHunger = 0;
    private int dealDamage = 1;
    private MyOptional<Block> block = MyOptional.empty();

    public Item(String id, String name, ItemType type, SpriteLoader.SPRITES sprite, ToolVariant toolVariant,
            int durability, boolean stackable, int dealDamage) {
        this.id = id;
        this.name = name;
        this.type = type;
        this.sprite = sprite;
        this.toolVariant = MyOptional.of(toolVariant);
        this.durability = durability;
        this.maxDurability = durability;
        this.stackable = stackable;
        this.dealDamage = dealDamage;
    }

    public Item(String id, String name, ItemType type, SpriteLoader.SPRITES sprite, ToolVariant toolVariant,
            double miningDecrease, int durability, boolean stackable) {
        this.id = id;
        this.name = name;
        this.type = type;
        this.sprite = sprite;
        this.toolVariant = MyOptional.of(toolVariant);
        this.miningDecrease = miningDecrease;
        this.durability = durability;
        this.maxDurability = durability;
        this.stackable = stackable;
    }

    public Item(String id, String name, ItemType type, SpriteLoader.SPRITES sprite, Block block) {
        this.id = id;
        this.name = name;
        this.type = type;
        this.sprite = sprite;
        this.block = MyOptional.of(block);
    }

    public Item(String id, String name, ItemType type, SpriteLoader.SPRITES sprite) {
        this.id = id;
        this.name = name;
        this.type = type;
        this.sprite = sprite;
    }

    public Item(String id, String name, ItemType type, SpriteLoader.SPRITES sprite, int addHunger) {
        this.id = id;
        this.name = name;
        this.type = type;
        this.sprite = sprite;
        this.addHunger = addHunger;
    }

    public boolean use() {
        durability--;
        if (durability == 0) {
            return true;
        }

        return false;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (o == null || getClass() != o.getClass())
            return false;
        Item item = (Item) o;

        return name.equals(item.name);
    }

    public void setSpriteState(Enum spriteState) {
        this.spriteState = MyOptional.of(spriteState);
    }
}
