import { Interaction } from 'discord.js';

import { subscriptions } from "../index";
import { ensureVoiceConnection, formatCallbackData, waitingForResponse } from "../utils";

const nothingToSkipResponse = formatCallbackData(`The queue is empty.`);

const skippedResponse = formatCallbackData(`The song has been skipped.`);

export const skipCommand = {
	name: "skip",
	description: "Skips the current song"
};

export async function skip( interaction: Interaction) {
	if (!interaction.guildId) return;
	await ensureVoiceConnection(interaction);
	const subscription = subscriptions.get(interaction.guildId);
	await interaction.followUp(waitingForResponse);

	if(!subscription.playing) {
		await interaction.editReply(nothingToSkipResponse);
	} else {
		await subscription.audioPlayer.stop();
		await interaction.editReply(skippedResponse);
	}	
}