package eu.mhsl.minecraft.pixelblocks.commands;

import eu.mhsl.minecraft.pixelblocks.PixelBlockItem;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.UUID;

public class GiveSubCommand extends SubCommand {
    public GiveSubCommand() {
        super("give", "pixelblocks.command.give", "pixelblocks.command.give.description");
    }

    @Override
    public void execute(@NotNull Player player, @NotNull String[] args) {
        UUID blockId;
        if(args.length == 0) {
            blockId = UUID.randomUUID();
        } else {
            try {
                blockId = UUID.fromString(args[0]);
            } catch(IllegalArgumentException e) {
                player.sendMessage(Component.translatable("pixelblocks.error.invalid-uuid", Component.text(args[0])).color(NamedTextColor.RED));
                return;
            }
        }

        ItemStack item = PixelBlockItem.getEmptyPixelBlock(player.locale());
        PixelBlockItem.setBlockId(item, blockId);

        player.getInventory().addItem(item);
        player.sendMessage(Component.translatable("pixelblocks.command.give.success", Component.text(blockId.toString())).color(NamedTextColor.GREEN));
    }

    @Override
    public @NotNull List<String> tabComplete(@NotNull Player player, @NotNull String[] args) {
        if(args.length == 1) return List.of("<uuid>");
        return List.of();
    }
}
