package me.proxylink.plugin.bungee;

import me.proxylink.plugin.PluginRuntime;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.plugin.Command;

import java.util.List;
import java.util.Locale;

final class DirtSimpleBungeeCommand extends Command {
    private final PluginRuntime runtime;

    DirtSimpleBungeeCommand(PluginRuntime runtime) {
        super("dsp2p", "dirtsimplep2p.command", "dirtsimplep2p");
        this.runtime = runtime;
    }

    @Override
    public void execute(CommandSender sender, String[] args) {
        String subcommand = args.length == 0 ? "status" : args[0].toLowerCase(Locale.ROOT);
        switch (subcommand) {
            case "status" -> sendBlock(sender, "DirtSimpleP2P Status", runtime.statusLines());
            case "doctor" -> sendBlock(sender, "DirtSimpleP2P Doctor", runtime.doctorLines());
            case "webwizard" -> sendBlock(sender, "DirtSimpleP2P Web Wizard", runtime.toggleWebWizardLines());
            default -> {
                send(sender, ChatColor.RED + "Usage: /dsp2p status, /dsp2p doctor, or /dsp2p webwizard");
            }
        }
    }

    private static void sendBlock(CommandSender sender, String title, List<String> lines) {
        send(sender, ChatColor.GOLD + title);
        for (String line : lines) {
            send(sender, ChatColor.GRAY + "- " + ChatColor.WHITE + line);
        }
    }

    private static void send(CommandSender sender, String message) {
        sender.sendMessage(TextComponent.fromLegacyText(message));
    }
}
