package com.avairebot.orion.contracts.commands;

import com.avairebot.orion.Orion;
import com.avairebot.orion.commands.CommandMessage;
import com.avairebot.orion.commands.CommandPriority;
import com.avairebot.orion.factories.RequestFactory;
import com.avairebot.orion.requests.Response;
import com.avairebot.orion.utilities.RandomUtil;
import net.dv8tion.jda.core.entities.Message;

import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;

public abstract class InteractionCommand extends Command {

    private final String interaction;

    public InteractionCommand(Orion orion, String interaction) {
        super(orion, false);

        this.interaction = interaction;
    }

    @Override
    public String getDescription() {
        return String.format("Sends the **%s** interaction to the mentioned user.", interaction);
    }

    @Override
    public List<String> getUsageInstructions() {
        return Collections.singletonList("`:command <user>`");
    }

    @Override
    public String getExampleUsage() {
        return "`:command @Orion`";
    }

    @Override
    public List<String> getMiddleware() {
        return Collections.singletonList("throttle:user,1,5");
    }

    @Override
    public CommandPriority getCommandPriority() {
        return CommandPriority.HIGH;
    }

    public abstract List<String> getInteractionImages();

    @Override
    public boolean onCommand(Message message, String[] args) {
        if (message.getMentionedUsers().isEmpty()) {
            return sendErrorMessage(message, "You must mention a use you want to use the interaction for.");
        }

        int imageIndex = RandomUtil.getInteger(getInteractionImages().size());

        message.getChannel().sendTyping().queue();
        RequestFactory.makeGET(getInteractionImages().get(imageIndex))
                .send((Consumer<Response>) response -> message.getChannel().sendFile(
                        response.getResponse().body().byteStream(),
                        interaction + "-" + imageIndex + ".gif",
                        new CommandMessage(String.format("**%s** %s **%s**",
                                message.getMember().getEffectiveName(),
                                interaction,
                                message.getGuild().getMember(message.getMentionedUsers().get(0)).getEffectiveName()
                        ))
                ).queue());
        return true;
    }
}

@@ -563,16 +563,53 @@
 raction;
+%0A    private final boolean overwrite;
 %0A%0A    pu
@@ -663,16 +663,35 @@
 eraction
+, boolean overwrite
 ) %7B%0A    
@@ -733,33 +733,182 @@
 his.
-interaction = interaction
+overwrite = overwrite;%0A        this.interaction = interaction;%0A    %7D%0A%0A    public InteractionCommand(Orion orion, String interaction) %7B%0A        this(orion, interaction, false)
 ;%0A  
@@ -2287,12 +2287,13 @@
     
-new 
+build
 Comm
@@ -2307,177 +2307,289 @@
 age(
-String.format(%22**%25s** %25s **%25s**%22,%0A                                message.getMember().getEffectiveName(),%0A                                interaction,%0A                  
+message)%0A                ).queue());%0A        return true;%0A    %7D%0A%0A    private CommandMessage buildCommandMessage(Message message) %7B%0A        if (overwrite) %7B%0A            return new CommandMessage(String.format(interaction,%0A                    message.getMember().getEffectiveName(),%0A
     
@@ -2590,32 +2590,38 @@
 ,%0A              
+      
 message.getGuild
@@ -2696,32 +2696,36 @@
             
+));%0A
         
     ))%0A     
@@ -2716,62 +2716,274 @@
     
+%7D%0A%0A
     
-))%0A                ).queue());%0A        return true
+    return new CommandMessage(String.format(%22**%25s** %25s **%25s**%22,%0A                message.getMember().getEffectiveName(),%0A                interaction,%0A                message.getGuild().getMember(message.getMentionedUsers().get(0)).getEffectiveName()%0A        ))
 ;%0A  

Make default interaction placeholder overwriteable