package jesse.keeblarcraft.Commands;

import com.mojang.brigadier.arguments.StringArgumentType;

import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.network.ServerPlayerEntity;

public class MailCommands {
    public void RegisterMailCommands() {
        // Mail send <player> msg...
        CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
            var mailRoot = CommandManager.literal("mail").build();
            var sendNode = CommandManager.literal("send").build();
            var playerName = CommandManager.argument("target_name", StringArgumentType.string()).build();
            var message = CommandManager.argument("mail_msg", StringArgumentType.greedyString())
                .executes(context -> SendMail(context.getSource().getPlayer(), StringArgumentType.getString(context, "target_name"), StringArgumentType.getString(context, "mail_msg")))
                .build();

            dispatcher.getRoot().addChild(mailRoot);

            mailRoot.addChild(sendNode);
            sendNode.addChild(playerName);
            playerName.addChild(message);
        });

        // Mail read
        CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
            var mailRoot = CommandManager.literal("mail").build();
            var readNode = CommandManager.literal("read")
                .executes(context -> ReadMail(context.getSource().getPlayer()))
                .build();

            dispatcher.getRoot().addChild(mailRoot);
            mailRoot.addChild(readNode);
        });

        // Mail clear
        CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
            var mailRoot = CommandManager.literal("mail").build();
            var clearNode = CommandManager.literal("clear")
                .executes(context -> ClearMail(context.getSource().getPlayer()))
                .build();

            dispatcher.getRoot().addChild(mailRoot);
            mailRoot.addChild(clearNode);
        });
    }

    private int SendMail(ServerPlayerEntity source, String targetName, String mail) {
        return 0;
    }

    private int ReadMail(ServerPlayerEntity player) {
        return 0;
    }

    private int ClearMail(ServerPlayerEntity player) {
        return 0;
    }
}
