package stream.flarebot.flarebot.commands.automod;

import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.entities.User;
import stream.flarebot.flarebot.commands.Command;
import stream.flarebot.flarebot.commands.CommandType;
import stream.flarebot.flarebot.mod.ModlogEvent;
import stream.flarebot.flarebot.objects.GuildWrapper;
import stream.flarebot.flarebot.objects.ReportStatus;
import stream.flarebot.flarebot.util.MessageUtils;

import java.awt.Color;
import java.util.Arrays;
import java.util.stream.Collectors;

public class ModlogCommand implements Command {

    @Override
    public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {

        if (args.length >= 2) {
            ModlogEvent event = null;
            boolean all = false;
            try {
                event = ModlogEvent.valueOf(MessageUtils.getMessage(args, 1).toUpperCase().replace(" ", "_"));
            } catch (IllegalArgumentException e) {
                if (args[1].equalsIgnoreCase("all")) {
                    all = true;
                } else {
                    EmbedBuilder errorBuilder = new EmbedBuilder();
                    errorBuilder.setDescription("Invalid Event: `" + args[1] + "`");
                    errorBuilder.addField("Events", "**" + Arrays.stream(ModlogEvent.values()).map(ModlogEvent::toString).collect(Collectors.joining("**\n**")) + "**", false);
                    MessageUtils.sendErrorMessage(errorBuilder, channel);
                    return;
                }
            }
            if (args[0].equalsIgnoreCase("enable")) {
                if (all) {
                    for (ModlogEvent modlogEvent : ModlogEvent.values()) {
                        guild.enableEvent(modlogEvent);
                    }
                    MessageUtils.sendSuccessMessage("Successfully enabled all events", channel, sender);
                } else {
                    if (guild.enableEvent(event)) {
                        MessageUtils.sendSuccessMessage("Successfully enabled event " + event.toString(), channel, sender);
                        return;
                    } else {
                        MessageUtils.sendErrorMessage("Error enabling event (Probably already enabled)", channel, sender);
                        return;
                    }
                }
            }
            if (args[0].equalsIgnoreCase("disable")) {
                if (all) {
                    for (ModlogEvent modlogEvent : ModlogEvent.values()) {
                        guild.disableEvent(modlogEvent);
                    }
                    MessageUtils.sendSuccessMessage("Successfully enabled all events", channel, sender);
                } else {
                    if (guild.disableEvent(event)) {
                        MessageUtils.sendSuccessMessage("Successfully enabled event " + event.toString(), channel, sender);
                        return;
                    } else {
                        MessageUtils.sendErrorMessage("Error enabling event (Probably already enabled)", channel, sender);
                        return;
                    }
                }
            }
            if (args[0].equalsIgnoreCase("compact")) {
                if (all) {
                    int compact = 0;
                    int uncompact = 0;
                    for (ModlogEvent modlogEvent : ModlogEvent.values()) {
                        if (modlogEvent.isCompact()) {
                            compact++;
                        } else {
                            uncompact++;
                        }
                    }
                    if (compact >= uncompact) {
                        for (ModlogEvent modlogEvent : ModlogEvent.values()) {
                            modlogEvent.setCompact(false);
                        }
                        MessageUtils.sendSuccessMessage("Un-compacted all the modlog events", channel, sender);
                        return;
                    } else {
                        for (ModlogEvent modlogEvent : ModlogEvent.values()) {
                            modlogEvent.setCompact(true);
                        }
                        MessageUtils.sendSuccessMessage("Compacted all the modlog events", channel, sender);
                        return;
                    }
                }
            }
            if (args[0].equalsIgnoreCase("setchannel")) {
                if (all) {
                    guild.getAutoModConfig().setModLogChannel(channel.getId());
                    MessageUtils.sendSuccessMessage("Set the modlog channel for ALL to " + channel.getAsMention(), channel, sender);
                    return;
                } else {
                    //Walshy
                }
            }
        }

        MessageUtils.sendUsage(this, channel, member.getUser(), args);

        //Old command. not sure if you want this still walshy
        /*if (!getPermissions(channel).hasPermission(member, "flarebot.modlog"))
            return;
        if (args.length == 1) {
            if (args[0].equalsIgnoreCase("setchannel")) {
                guild.getAutoModConfig()
                        .setModLogChannel(channel.getId());
                channel.sendMessage(new EmbedBuilder().setColor(Color.green)
                        .setDescription("The modlog channel has been changed to " + channel
                                .getAsMention()).build()).queue();
            }
            *//*} else if (args[0].equalsIgnoreCase("config")) {
            } else if (args[0].equalsIgnoreCase("set")) {

            } else {
                MessageUtils.sendErrorMessage("Invalid argument!", channel);
            }
        } else if (args.length == 2) {

        } else if (args.length == 3) {*//*

        } else {
            MessageUtils.sendUsage(this, channel, sender);
        }*/
    }

    @Override
    public String getCommand() {
        return "modlog";
    }

    @Override
    public String getDescription() {
        return "Set the channel where mod events can be logged.";
    }

    @Override
    public String getUsage() {
        return "`{%}modlog enable|disable <feature>` - Enables or disables a modlog feature.\n" +
                "`{%}modlog compact <feature>` - Toggles the compacting of modlog features (Compacted is plain text).\n" +
                "`{%}modlog setchannel <feature>` - Sets the modlog channel.";
        /*return "`{%}modlog setchannel` - Set the modlog to be displayed in this channel.\n";
                *//*+ "`{%}modlog config` - View the config of the modlog.\n"
                + "`{%}modlog set <configOption> <value>` - Set config options";*/
    }

    @Override
    public String getExtraInfo() {
        return "**Features:**\n" +
                "`MEMBER_JOIN` - Triggers when user joins the server.\n" +
                "`MEMBER_LEAVE` - Triggers when user leaves the server.\n\n" +
                "`MEMBER_ROLE_GIVE` - Triggers when a role is added to a user.\n" +
                "`MEMBER_ROLE_REMOVE` - Triggers when a role is taken away a user.\n\n" +
                "`MEMBER_VOICE_JOIN` - Triggers when a user joins a voice channel.\n" +
                "`MEMBER_VOICE_LEAVE` - Triggers when a user leaves a voice channel.\n\n" +
                "`ROLE_CREATE` - Triggers when a role is created.\n" +
                "`ROLE_DELETE` - Triggers when a role is deleted.\n\n" +
                "`CHANNEL_CREATE` - Triggers when a channel is created.\n" +
                "`CHANNEL_DELETE` - Triggers when a channel is deleted.\n\n" +
                "`COMMAND` - Triggers when a user runs a **FlareBot** command.\n\n" +
                "`MESSAGE_DELETE` - Triggers when a message is deleted.\n\n" +
                "`all` - This is for targeting everything.";
    }

    @Override
    public CommandType getType() {
        return CommandType.MODERATION;
    }
}

@@ -1463,18 +1463,17 @@
 ents%22, %22
-**
+%60
 %22 + Arra
@@ -1563,23 +1563,20 @@
 ng(%22
-**%5Cn**
+%60%5Cn%60
 %22)) + %22
-**
+%60
 %22, f
@@ -5028,1021 +5028,8 @@
 gs);
-%0A%0A        //Old command. not sure if you want this still walshy%0A        /*if (!getPermissions(channel).hasPermission(member, %22flarebot.modlog%22))%0A            return;%0A        if (args.length == 1) %7B%0A            if (args%5B0%5D.equalsIgnoreCase(%22setchannel%22)) %7B%0A                guild.getAutoModConfig()%0A                        .setModLogChannel(channel.getId());%0A                channel.sendMessage(new EmbedBuilder().setColor(Color.green)%0A                        .setDescription(%22The modlog channel has been changed to %22 + channel%0A                                .getAsMention()).build()).queue();%0A            %7D%0A            *//*%7D else if (args%5B0%5D.equalsIgnoreCase(%22config%22)) %7B%0A            %7D else if (args%5B0%5D.equalsIgnoreCase(%22set%22)) %7B%0A%0A            %7D else %7B%0A                MessageUtils.sendErrorMessage(%22Invalid argument!%22, channel);%0A            %7D%0A        %7D else if (args.length == 2) %7B%0A%0A        %7D else if (args.length == 3) %7B*//*%0A%0A        %7D else %7B%0A            MessageUtils.sendUsage(this, channel, sender);%0A        %7D*/
 %0A   

Remove old command