package fr.Skydust.JdrBot.cmds;

import fr.Skydust.JdrBot.bases.CommandManager.CommandsManager;
import fr.Skydust.JdrBot.bases.command.Command;
import fr.Skydust.JdrBot.bases.command.CommandSpec;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;

import java.awt.*;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@CommandSpec(
        name = "aide|help",
        description = "Pour avoir de l'aide !"
)
public class Aide extends Command {
    @Override
    public void call(MessageReceivedEvent e) {
        StringBuilder sb = new StringBuilder();

        for (int currentCommandCount = 0; currentCommandCount < CommandsManager.getCommandList().size(); currentCommandCount++)
        {
            Command cmd = CommandsManager.getCommandList().get(currentCommandCount);
            if(!cmd.hidden) {
                sb.append("`")
                        .append(cmd.cmdName)
                        .append((cmd.cmdUsage.isEmpty()) ? "" : " " + cmd.cmdUsage)
                        .append("` - *")
                        .append(cmd.cmdDesc)
                        .append("*")
                        .append((currentCommandCount != CommandsManager.getCommandList().size() - 1) ? "\n" : "");
            }
        }

        e.getChannel().sendMessage(new MessageCreateBuilder().setEmbeds(new EmbedBuilder()
                .setDescription(sb.toString())
                .setTitle("Aide", null)
                .setFooter("Fait le " + LocalDateTime.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy 'a' HH:mm:ss")), e.getJDA().getSelfUser().getAvatarUrl())
                .setColor(Color.red)
                .build()).build()).queue();
    }
}
