/**
 * /listskor — Show all pending ranked matches with their IDs.
 */

import { SlashCommandBuilder, PermissionFlagsBits } from 'discord.js';
import { getPendingMatches } from '../api.js';
import { pendingMatchesEmbed, errorEmbed } from '../embeds.js';

export const data = new SlashCommandBuilder()
    .setName('listskor')
    .setDescription('Tampilkan pertandingan ranked yang belum selesai')
    .setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild);

export async function execute(interaction) {
    await interaction.deferReply({ ephemeral: true }); // only visible to the caller

    try {
        const { matches } = await getPendingMatches();
        const embed = pendingMatchesEmbed(matches, 'Pertandingan Ranked Aktif');
        await interaction.editReply({ embeds: [embed] });
    } catch (err) {
        await interaction.editReply({ embeds: [errorEmbed(err.message)] });
    }
}
