package com.tisawesomeness.minecord.command.admin;

import com.tisawesomeness.minecord.command.Command;
import com.tisawesomeness.minecord.command.CommandContext;
import com.tisawesomeness.minecord.database.Database;
import com.tisawesomeness.minecord.debug.ChannelCacheDebugOption;
import com.tisawesomeness.minecord.debug.DebugOption;
import com.tisawesomeness.minecord.debug.GuildCacheDebugOption;
import com.tisawesomeness.minecord.debug.JDADebugOption;
import com.tisawesomeness.minecord.debug.ThreadDebugOption;
import com.tisawesomeness.minecord.debug.UserCacheDebugOption;

import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.sharding.ShardManager;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class DebugCommand extends Command {
    public CommandInfo getInfo() {
        return new CommandInfo(
            "debug",
            "Prints out debug info.",
            "[option]",
            new String[]{"dump"},
            0,
            true,
            true,
            false
        );
    }

    private final List<DebugOption> debugOptions;
    public DebugCommand(ShardManager sm, Database db) {
        debugOptions = Arrays.asList(
                new JDADebugOption(sm),
                new ThreadDebugOption(),
                new GuildCacheDebugOption(db),
                new ChannelCacheDebugOption(db),
                new UserCacheDebugOption(db)
        );
    }

    public Result run(CommandContext txt) {
        if (!txt.config.debugMode) {
            return new Result(Outcome.WARNING, "The bot is not in debug mode.");
        }

        if (txt.args.length == 0) {
            String possibleOptions = debugOptions.stream()
                    .map(d -> String.format("`%s`", d.getName()))
                    .collect(Collectors.joining(", "));
            return new Result(Outcome.SUCCESS, "Possible options: " + possibleOptions);
        }

        for (DebugOption d : debugOptions) {
            if (d.getName().equalsIgnoreCase(txt.args[0])) {
                String debugInfo = d.debug();
                User author = txt.e.getAuthor();
                String requestedBy = String.format("Requested By %s (%s)\n", author.getAsTag(), author.getId());
                System.out.println("\n" + requestedBy + debugInfo + "\n"); // Useful to have in console
                return new Result(Outcome.SUCCESS, debugInfo);
            }
        }
        return new Result(Outcome.WARNING, ":warning: Not a valid debug option.");
    }
}

@@ -666,16 +666,63 @@
 Manager;
+%0Aimport net.dv8tion.jda.api.utils.MarkdownUtil;
 %0A%0Aimport
@@ -1801,30 +1801,31 @@
  -%3E 
-String.format(%22%60%25s%60%22, 
+MarkdownUtil.monospace(
 d.ge
@@ -2001,102 +2001,96 @@
     
-for (DebugOption d : debugOptions) %7B%0A            if (d.getName().equalsIgnoreCase(txt.args%5B0%5D)
+if (txt.args%5B0%5D.equalsIgnoreCase(%22all%22)) %7B%0A            for (DebugOption d : debugOptions
 ) %7B%0A
@@ -2155,21 +2155,33 @@
     
-User author =
+printToConsole(debugInfo,
  txt
@@ -2194,16 +2194,17 @@
 Author()
+)
 ;%0A      
@@ -2217,375 +2217,763 @@
     
-String requestedBy = String.format(%22Requested By %25s (%25s)%5Cn%22, author.getAsTag(), author.getId());%0A                System.out.println(%22%5Cn%22 + requestedBy + debugInfo + %22%5Cn%22); // Useful to have in console%0A                return new Result(Outcome.SUCCESS, debugInfo);%0A            %7D%0A        %7D%0A        return new Result(Outcome.WARNING, %22:warning: Not a valid debug option.
+txt.e.getChannel().sendMessage(debugInfo).queue();%0A            %7D%0A            return new Result(Outcome.SUCCESS);%0A        %7D%0A%0A        for (DebugOption d : debugOptions) %7B%0A            if (d.getName().equalsIgnoreCase(txt.args%5B0%5D)) %7B%0A                String debugInfo = d.debug();%0A                printToConsole(debugInfo, txt.e.getAuthor());%0A                return new Result(Outcome.SUCCESS, debugInfo);%0A            %7D%0A        %7D%0A        return new Result(Outcome.WARNING, %22:warning: Not a valid debug option.%22);%0A    %7D%0A%0A    private static void printToConsole(String debugInfo, User author) %7B%0A        String requestedBy = String.format(%22Requested By %25s (%25s)%5Cn%22, author.getAsTag(), author.getId());%0A        System.out.println(%22%5Cn%22 + requestedBy + debugInfo + %22%5Cn
 %22);%0A

Add &debug all