package stream.flarebot.flarebot.commands.general;

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 org.apache.commons.lang3.StringUtils;
import stream.flarebot.flarebot.commands.Command;
import stream.flarebot.flarebot.commands.CommandType;
import stream.flarebot.flarebot.objects.GuildWrapper;
import stream.flarebot.flarebot.util.MessageUtils;

import java.awt.Color;

public class TagsCommand implements Command {

    @Override
    public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message message, String[] args, Member member) {
        if (args.length == 0) {
            if (guild.getTags().isEmpty()) {
                MessageUtils.sendErrorMessage("There are currently no tags for this guild!\n" +
                        "Add a tag via `{%}tags add <tag_name> <tag_message>`.", channel);
                return;
            }
            channel.sendMessage(MessageUtils.getEmbed(sender).setTitle("Guild Tags", null).setColor(Color.CYAN)
                    .setDescription("```\n" + StringUtils.join(guild.getTags().keySet(), ", ") + "\n```")
                    .build()).queue();
        } else if (args.length == 1) {
            if (guild.getTags().containsKey(args[0].toLowerCase()))
                channel.sendMessage(guild.getTags().get(args[0].toLowerCase())).queue();
            else
                MessageUtils.sendErrorMessage("This tag doesn't exist!", channel);
        } else if (args.length == 2) {
            if (args[0].equalsIgnoreCase("add")) {
                MessageUtils.sendErrorMessage("This seems to be invalid ¯\\_(ツ)_/¯\n"
                        + "Usage: `{%}tags add " + args[1] + " <tag_message>`", channel);
            } else if (args[0].equalsIgnoreCase("remove")) {
                if (guild.getTags().containsKey(args[1].toLowerCase())) {
                    guild.getTags().remove(args[1]);
                    MessageUtils.sendSuccessMessage("You successfully removed the tag `" + args[1] + "`!",
                            channel, sender);
                } else
                    MessageUtils.sendErrorMessage("This tag doesn't exist!", channel);
            } else
                MessageUtils.sendErrorMessage("That is an invalid argument!", channel);
        } else {
            if (args[0].equalsIgnoreCase("add")) {
                if (guild.getTags().containsKey(args[1].toLowerCase())) {
                    MessageUtils.sendErrorMessage("This tag already exists!", channel);
                    return;
                }

                guild.getTags().put(args[1].toLowerCase(), MessageUtils.getMessage(args, 2));
                MessageUtils.sendSuccessMessage("You successfully added the tag `" + args[1] + "`!", channel,
                        sender);
            } else
                MessageUtils.sendErrorMessage("That is an invalid argument!", channel);
        }
    }

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

    @Override
    public String getDescription() {
        return "Allows user to save chunks of texts as 'tags' and view them in the future";
    }

    @Override
    public String getUsage() {
        return "`{%}tags` - Lists the existing tags\n" +
                "`{%}tags <tag_name>` - Sends the tag message\n" +
                "`{%}tags add <tag_name> <tag_message>` - Adds a tag to the guild\n" +
                "`{%}tags remove <tag_name>` - Removes a tag from the guild";
    }

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

    @Override
    public String[] getAliases() {
        return new String[]{"tag"};
    }

    @Override
    public boolean isBetaTesterCommand() {
        return true;
    }
}

@@ -2174,33 +2174,35 @@
           %7D else
+ %7B
 %0A
-
                 
@@ -2276,38 +2276,294 @@
 l);%0A            
-%7D else
+    %7D%0A            %7D else if (args%5B0%5D.equalsIgnoreCase(%22edit%22)) %7B%0A                MessageUtils.sendErrorMessage(%22This seems to be invalid %C2%AF%5C%5C_(%E3%83%84)_/%C2%AF%5Cn%22%0A                        + %22Usage: %60%7B%25%7Dtags edit %22 + args%5B1%5D + %22 %3Ctag_message%3E%60%22, channel);%0A            %7D else %7B
 %0A               
@@ -2627,32 +2627,46 @@
 nt!%22, channel);%0A
+            %7D%0A
         %7D else %7B
@@ -3177,24 +3177,532 @@
       %7D else
+ if (args%5B0%5D.equalsIgnoreCase(%22edit%22)) %7B%0A                if (!guild.getTags().containsKey(args%5B1%5D.toLowerCase())) %7B%0A                    MessageUtils.sendErrorMessage(%22This tag doesn't exist!%22, channel);%0A                    return;%0A                %7D%0A%0A                guild.getTags().put(args%5B1%5D.toLowerCase(), MessageUtils.getMessage(args, 2));%0A                MessageUtils.sendSuccessMessage(%22You successfully edited the tag %60%22 + args%5B1%5D + %22%60!%22, channel,%0A                        sender);%0A            %7D else %7B
 %0A           
@@ -3770,32 +3770,46 @@
 nt!%22, channel);%0A
+            %7D%0A
         %7D%0A    %7D%0A
@@ -4201,24 +4201,24 @@
 essage%5Cn%22 +%0A
-
             
@@ -4288,24 +4288,118 @@
  guild%5Cn%22 +%0A
+                %22%60%7B%25%7Dtags edit %3Ctag_name%3E %3Ctag_message%3E%60 - Edits an already existing tag%5Cn%22 +%0A
             

Edit args for tags