package com.nincraft.ninbot.components.command;

import com.nincraft.ninbot.components.admin.AdminCommand;
import com.nincraft.ninbot.components.adventure.RollCommand;
import com.nincraft.ninbot.components.event.EventCommand;
import com.nincraft.ninbot.components.event.EventDao;
import com.nincraft.ninbot.components.event.EventScheduler;
import com.nincraft.ninbot.components.fun.DabCommand;
import com.nincraft.ninbot.components.info.HelpCommand;
import com.nincraft.ninbot.components.info.ListCommand;
import com.nincraft.ninbot.components.info.StatsCommand;
import com.nincraft.ninbot.components.poll.PollCommand;
import com.nincraft.ninbot.components.subscribe.SubscribeCommand;
import com.nincraft.ninbot.components.subscribe.UnsubscribeCommand;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import net.dv8tion.jda.core.hooks.ListenerAdapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class CommandListener extends ListenerAdapter {

    private CommandParser commandParser;
    @Value("${debugEnabled:false}")
    private boolean debugEnabled;
    @Autowired
    private List<String> roleBlackList;

    @Autowired
    public CommandListener(EventDao eventDao, EventScheduler eventScheduler) {
        commandParser = new CommandParser();
        commandParser.addCommand(new SubscribeCommand(roleBlackList));
        commandParser.addCommand(new UnsubscribeCommand(roleBlackList));
        commandParser.addCommand(new ListCommand(roleBlackList));
        commandParser.addCommand(new EventCommand(eventDao, eventScheduler));
        commandParser.addCommand(new StatsCommand(roleBlackList));
        commandParser.addCommand(new AdminCommand());
        commandParser.addCommand(new DabCommand());
        commandParser.addCommand(new PollCommand());
        commandParser.addCommand(new RollCommand());
        commandParser.addCommand(new HelpCommand(commandParser));
    }

    @Override
    public void onMessageReceived(MessageReceivedEvent event) {
        if (isNinbotMention(event) && checkDebug(event.getChannel().getName())) {
            commandParser.parseEvent(event);
        }
    }

    private boolean checkDebug(String channelName) {
        return !debugEnabled || channelName.equals("admin-test");
    }

    private boolean isNinbotMention(MessageReceivedEvent event) {
        return !event.getAuthor().isBot() && event.getMessage().getContentStripped().toLowerCase().startsWith("@ninbot");
    }
}

@@ -1239,63 +1239,8 @@
 led;
-%0A    @Autowired%0A    private List%3CString%3E roleBlackList;
 %0A%0A  
@@ -1327,16 +1327,44 @@
 cheduler
+, List%3CString%3E roleBlackList
 ) %7B%0A    

Fix autowire