import { Interaction } from 'discord.js';

import { subscriptions } from "../index.js";
import { MusicSubscription } from '../subscription';
import { ensureVoiceConnection, formatCallbackData, waitingForResponse } from "../utils";

const alreadyPausedResponse = formatCallbackData(`The player is already paused.`);

const emptyQueueResponse = formatCallbackData(`There's nothing in the queue right now.`);

const nowPausedResponse = formatCallbackData(`The player has been paused.`);

export const pauseCommand = {
	name: "pause",
	description: "Pauses the player"
};

export const stopCommand = {
	name: "stop",
	description: "Pauses the player, alias for /pause"
};

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

	if(subscription.playing) {
		if(player.nowPlaying) {
			await subscription.audioPlayer.pause();
			subscription.playing = false;
			await interaction.editReply(nowPausedResponse);
		} else {
			await interaction.editReply(emptyQueueResponse);
		}
	} else {
		await interaction.editReply(alreadyPausedResponse);
	}
	
}