package land.chipmunk.chipmunkmod.commands;

import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import land.chipmunk.chipmunkmod.modules.SelfCare;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.network.chat.Component;

import static com.mojang.brigadier.arguments.BoolArgumentType.bool;
import static com.mojang.brigadier.arguments.BoolArgumentType.getBool;
import static land.chipmunk.chipmunkmod.command.CommandManager.argument;
import static land.chipmunk.chipmunkmod.command.CommandManager.literal;

public class SelfCareCommand {
    public static void register (final CommandDispatcher<FabricClientCommandSource> dispatcher) {
        dispatcher.register(
                literal("selfcare")
                        .then(
                                literal("op")
                                        .then(
                                                argument("boolean", bool())
                                                        .executes(m -> setSelfCare(m, "op"))
                                        )
                        )
                        .then(
                                literal("gamemode")
                                        .then(
                                                argument("boolean", bool())
                                                        .executes(m -> setSelfCare(m, "gamemode"))
                                        )
                        )
                        .then(
                                literal("cspy")
                                        .then(
                                                argument("boolean", bool())
                                                        .executes(m -> setSelfCare(m, "cspy"))
                                        )
                        )
        );
    }

    public static int setSelfCare (final CommandContext<FabricClientCommandSource> context, final String type) {
        final FabricClientCommandSource source = context.getSource();
        final boolean bool = getBool(context, "boolean");

        switch (type) {
            case "op" -> {
                SelfCare.INSTANCE.configOpEnabled = bool;
                source.sendFeedback(Component.literal("The op self care is now " + (bool ? "enabled" : "disabled")));
            }
            case "gamemode" -> {
                SelfCare.INSTANCE.configGameModeEnabled = bool;
                source.sendFeedback(Component.literal("The gamemode self care is now " + (bool ? "enabled" : "disabled")));
            }
            case "cspy" -> {
                SelfCare.INSTANCE.configCommandSpyEnabled = bool;
                source.sendFeedback(Component.literal("The CommandSpy self care is now " + (bool ? "enabled" : "disabled")));
            }
        }

        return Command.SINGLE_SUCCESS;
    }
}
