package fr.Skydust.JdrBot.cmds.record;

import fr.Skydust.JdrBot.bases.command.Command;
import fr.Skydust.JdrBot.bases.command.CommandSpec;
import fr.Skydust.JdrBot.cmds.playmusic.PlayMusic;
import fr.Skydust.JdrBot.stock.RecordState;
import fr.Skydust.JdrBot.enums.MessageType;
import fr.Skydust.JdrBot.utils.Utils;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;

@CommandSpec(
        name = "stoprecord|sr",
        description = "Arrete et archive l'enregistrement"
)
public class StopRecord extends Command {
    @Override
    public void call(MessageReceivedEvent e) {
        RecordState rs = Record.getGuildRecordState(e.getGuild());
        if(rs.isRecording) {
            if(PlayMusic.getGuildsJukebox(e.getGuild()) == null) {
                e.getGuild().getAudioManager().closeAudioConnection();
            }
            rs.endRecord(e.getGuild(), (TextChannel) e.getChannel());
        } else {
            Utils.sendMessage(e.getChannel(), MessageType.ERROR, "Il n'y a aucun enregistrement en cours");
        }
    }
}
