package me.trouper.sentinel.server.commands;

import io.github.itzispyder.pdk.commands.Args;
import io.github.itzispyder.pdk.commands.CommandRegistry;
import io.github.itzispyder.pdk.commands.Permission;
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
import me.trouper.sentinel.utils.PlayerUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.Map;
import java.util.UUID;

@CommandRegistry(value = "reply", permission = @Permission("sentinel.reply"),printStackTrace = true)
public class ReplyCommand implements QuickCommand {

    public static Map<UUID, UUID> replyMap = main.dir().messageHandler.replyMap;

    @Override
    public void dispatchCommand(CommandSender sender, Command command, String s, Args args) {
        String name = sender.getName();
        Player p = sender.getServer().getPlayer(name);
        UUID senderID = p.getUniqueId();
        if (replyMap.get(senderID) == null) {
            errorAny(sender,main.dir().io.lang.playerInteraction.noReply);
        }
        Player r = sender.getServer().getPlayer(replyMap.get(senderID));
        UUID reciverID = r.getUniqueId();
        if (args.get(0).toString() == null) {
            errorAny(sender,main.dir().io.lang.playerInteraction.noMessageProvided);
        }
        String msg = args.getAll().toString();
        if (PlayerUtils.checkPermission(sender,"sentinel.message")) {
            main.dir().messageHandler.messagePlayer(p,r,msg);
            replyMap.put(senderID,reciverID);
        }
    }

    @Override
    public void dispatchCompletions(CommandSender commandSender, Command command, String s, CompletionBuilder b) {
        b.then(b.arg("[<Message>]"));
    }
}
