// SPDX-FileCopyrightText: 2023 The CC: Tweaked Developers
//
// SPDX-License-Identifier: MPL-2.0

package dan200.computercraft.shared.turtle.inventory;

import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.impl.TurtleUpgrades;
import net.minecraft.core.HolderLookup;
import net.minecraft.resources.Identifier;
import net.minecraft.world.Container;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import org.jspecify.annotations.Nullable;

/**
 * A slot in the turtle UI which holds the turtle's current upgrade.
 *
 * @see TurtleMenu
 */
public class UpgradeSlot extends Slot {
    public static final Identifier LEFT_UPGRADE = Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "gui/turtle_upgrade_left");
    public static final Identifier RIGHT_UPGRADE = Identifier.fromNamespaceAndPath(ComputerCraftAPI.MOD_ID, "gui/turtle_upgrade_right");

    private final HolderLookup.Provider registries;
    private final TurtleSide side;

    public UpgradeSlot(Container container, HolderLookup.Provider registries, TurtleSide side, int slot, int xPos, int yPos) {
        super(container, slot, xPos, yPos);
        this.registries = registries;
        this.side = side;
    }

    @Override
    public boolean mayPlace(ItemStack stack) {
        return TurtleUpgrades.instance().get(registries, stack) != null;
    }

    @Override
    public int getMaxStackSize() {
        return 1;
    }

    @Nullable
    @Override
    public Identifier getNoItemIcon() {
        return side == TurtleSide.LEFT ? LEFT_UPGRADE : RIGHT_UPGRADE;
    }
}
