package lnmpro.Commands;

import lnmpro.Main;
import org.bukkit.Bukkit;
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.List;
import java.util.UUID;

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

    public DenyDuelCommand(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 (player.hasMetadata("DueledBy")) {
                UUID targetUUID = UUID.fromString(player.getMetadata("DueledBy").get(0).asString());
                Player enemy = Bukkit.getPlayer(targetUUID);
                String gamemode = player.getMetadata("DueledWithGamemode").get(0).asString();
                enemy.sendMessage("nem cica " + gamemode);
                player.sendMessage("nem cica " + gamemode);
                player.removeMetadata("DueledBy", plugin);
                player.removeMetadata("DueledWithGamemode", plugin);
            }
        } else {
            sender.sendMessage("nem vagy player nem fog sikerulni");
        }
        return true;
    }

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