package org.bukkit.inventory;

import com.bergerkiller.generated.org.bukkit.inventory.MainHandHandle;

class Inventory {

    // These functions were introduced since 1.10.2
    public optional org.bukkit.Location getLocation();
    public optional org.bukkit.inventory.ItemStack[] getStorageContents();
    public optional void setStorageContents(org.bukkit.inventory.ItemStack[] items);

    // These functions disappeared in MC 1.14
    public optional String getName();
    public optional String getTitle();

    // Paperspigot only, it seems
    public transient optional java.util.HashMap<Integer, org.bukkit.inventory.ItemStack> removeItemAnySlot(org.bukkit.inventory.ItemStack[] items);
}

// Note: This is a class on 1.8 - 1.20.6, but is an interface on 1.21+
// For binary compatibility we have to defer to generated code for this reason
class InventoryView {
    public abstract void close();
    public abstract org.bukkit.entity.HumanEntity getPlayer();
    public abstract org.bukkit.inventory.Inventory getTopInventory();
    public abstract org.bukkit.inventory.Inventory getBottomInventory();
    public abstract org.bukkit.inventory.ItemStack getItem(int index);
    public abstract void setItem(int index, org.bukkit.inventory.ItemStack item);
}

optional class MainHand {
    enum (MainHandHandle) MainHand LEFT;
    enum (MainHandHandle) MainHand RIGHT;
}

class PlayerInventory extends Inventory {
    public optional abstract void setItemInMainHand(ItemStack item);
    public optional abstract void setItemInOffHand(ItemStack item)

    // Deprecated <= 1.8.9
    public optional abstract ItemStack getItemInHand()
    public optional abstract void setItemInHand(ItemStack stack)

#if version >= 1.9
    public ItemStack getItemInMainHand();
    public ItemStack getItemInOffHand();
#else
    public ItemStack getItemInMainHand:getItemInHand();
    public ItemStack getItemInOffHand() {
        return null;
    }
#endif

#if version >= 1.20.5
    #require org.bukkit.inventory.PlayerInventory public boolean isEquipmentSlotSupported(EquipmentSlot slot) {
        // BODY slot isn't supported for players
        return slot != EquipmentSlot.BODY;
    }

    public void setItem(EquipmentSlot slot, ItemStack item) {
        if (instance#isEquipmentSlotSupported(slot)) {
            instance.setItem(slot, item);
        }
    }
    public ItemStack getItem(EquipmentSlot slot) {
        if (instance#isEquipmentSlotSupported(slot)) {
            return instance.getItem(slot);
        } else {
            return null;
        }
    }
#elseif version >= 1.16
    public boolean isEquipmentSlotSupported(EquipmentSlot slot) {
        return true; // All slots always work
    }
    public void setItem(EquipmentSlot slot, ItemStack item);
    public ItemStack getItem(EquipmentSlot slot);
#else
    public boolean isEquipmentSlotSupported(EquipmentSlot slot) {
        return true; // All slots always work
    }
    public void setItem(EquipmentSlot slot, ItemStack item) {
  #if version >= 1.9
        if (slot == EquipmentSlot.HAND)
            instance.setItemInMainHand(item);
        else if (slot == EquipmentSlot.OFF_HAND)
            instance.setItemInOffHand(item);
  #else
        if (slot == EquipmentSlot.HAND)
            instance.setItemInHand(item);
  #endif
        else if (slot == EquipmentSlot.FEET)
            instance.setBoots(item);
        else if (slot == EquipmentSlot.LEGS)
            instance.setLeggings(item);
        else if (slot == EquipmentSlot.CHEST)
            instance.setChestplate(item);
        else if (slot == EquipmentSlot.HEAD)
            instance.setHelmet(item);
    }
    public ItemStack getItem(EquipmentSlot slot) {
  #if version >= 1.9
        if (slot == EquipmentSlot.HAND)
            return instance.getItemInMainHand();
        else if (slot == EquipmentSlot.OFF_HAND)
            return instance.getItemInOffHand();
  #else
        if (slot == EquipmentSlot.HAND)
            return instance.getItemInHand();
  #endif
        else if (slot == EquipmentSlot.FEET)
            return instance.getBoots();
        else if (slot == EquipmentSlot.LEGS)
            return instance.getLeggings();
        else if (slot == EquipmentSlot.CHEST)
            return instance.getChestplate();
        else if (slot == EquipmentSlot.HEAD)
            return instance.getHelmet();
        else
            return null;
    }
#endif
}
