package de.winniepat.citrus.client;

import com.mojang.brigadier.Command;
import com.mojang.brigadier.arguments.StringArgumentType;
import de.winniepat.citrus.cosmetics.ClientCosmeticManager;
import de.winniepat.citrus.cosmetics.CosmeticScreen;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.minecraft.text.Text;

import java.util.UUID;

public class CosmeticCommands {
    public static void register() {
        ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(ClientCommandManager.literal("cosmetic")
                .then(ClientCommandManager.literal("wings")
                        .then(ClientCommandManager.literal("toggle")
                                .executes(context -> {
                                    UUID uuid = context.getSource().getPlayer().getUuid();
                                    ClientCosmeticManager.toggleWings(uuid);
                                    context.getSource().sendFeedback(Text.of("Toggled wings visibility"));
                                    return Command.SINGLE_SUCCESS;
                                })
                        )
                        .then(ClientCommandManager.literal("set")
                                .then(ClientCommandManager.argument("type", StringArgumentType.string())
                                        .executes(context -> {
                                            UUID uuid = context.getSource().getPlayer().getUuid();
                                            String type = StringArgumentType.getString(context, "type");
                                            ClientCosmeticManager.setActiveWings(uuid, type);
                                            context.getSource().sendFeedback(Text.of("Set wings to: " + type));
                                            return Command.SINGLE_SUCCESS;
                                        })
                                )
                        )
                )
                .then(ClientCommandManager.literal("hat")
                        .then(ClientCommandManager.literal("toggle")
                                .executes(context -> {
                                    UUID uuid = context.getSource().getPlayer().getUuid();
                                    ClientCosmeticManager.toggleHat(uuid);
                                    context.getSource().sendFeedback(Text.of("Toggled hat visibility"));
                                    return Command.SINGLE_SUCCESS;
                                })
                        )
                        .then(ClientCommandManager.literal("set")
                                .then(ClientCommandManager.argument("type", StringArgumentType.string())
                                        .executes(context -> {
                                            UUID uuid = context.getSource().getPlayer().getUuid();
                                            String type = StringArgumentType.getString(context, "type");
                                            ClientCosmeticManager.setActiveHat(uuid, type);
                                            context.getSource().sendFeedback(Text.of("Set hat to: " + type));
                                            return Command.SINGLE_SUCCESS;
                                        })
                                )
                        )
                )
                .then(ClientCommandManager.literal("halo")
                        .then(ClientCommandManager.literal("toggle")
                                .executes(context -> {
                                    UUID uuid = context.getSource().getPlayer().getUuid();
                                    ClientCosmeticManager.toggleHalo(uuid);
                                    context.getSource().sendFeedback(Text.of("Toggled halo visibility"));
                                    return Command.SINGLE_SUCCESS;
                                })
                        )
                        .then(ClientCommandManager.literal("set")
                                .then(ClientCommandManager.argument("type", StringArgumentType.string())
                                        .executes(context -> {
                                            UUID uuid = context.getSource().getPlayer().getUuid();
                                            String type = StringArgumentType.getString(context, "type");
                                            ClientCosmeticManager.setActiveHalo(uuid, type);
                                            context.getSource().sendFeedback(Text.of("Set halo to: " + type));
                                            return Command.SINGLE_SUCCESS;
                                        })
                                )
                        )
                )
                .then(ClientCommandManager.literal("gui")
                        .executes(context -> {
                            context.getSource().getClient().setScreen(new CosmeticScreen());
                            return Command.SINGLE_SUCCESS;
                        })
                )
        ));
    }
}