package hu.jgj52.pvpcore.Commands;

import hu.jgj52.pvpcore.Main;
import hu.jgj52.pvpcore.Utils.Kits;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.*;

public class CreateKitCommand implements CommandExecutor, TabCompleter {
    private final Main plugin;

    public CreateKitCommand(Main plugin) {
        this.plugin = plugin;
    }

    @Override
    public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) {
        if (sender instanceof Player player) {
            if (args.length == 1) {
                String base64 = Kits.itemStackArrayToBase64(player.getInventory().getContents());

                Map<String, Object> data = new HashMap<>();
                data.put("name", args[0]);
                data.put("content", base64);

                plugin.db.from("pvpcore_kits").insert(data);
                player.sendMessage("§aKit sikeresen létrehozva!");
            } else {
                sender.sendMessage("§cUsage: /createkit <name>");
            }
        }
        return true;
    }

    @Override
    public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) {
        return List.of();
    }
}
