import { SlashCommandBuilder } from "discord.js";
import type { CommandModule } from "../../discord/types.js";
import { notifyService } from "../../services/notify/notify-service.js";

export const scheduleCommand: CommandModule = {
  data: new SlashCommandBuilder()
    .setName("notify_schedule")
    .setDescription("예약 알림 규칙을 만듭니다")
    .addChannelOption((opt) => opt.setName("channel").setDescription("알림 채널").setRequired(true))
    .addStringOption((opt) => opt.setName("cron").setDescription("크론 식 (예: 0 9 * * *)").setRequired(true))
    .addStringOption((opt) => opt.setName("message").setDescription("알림 메시지").setRequired(true)),
  async execute(interaction) {
    if (!interaction.guildId) return;
    const channel = interaction.options.getChannel("channel", true);
    const cronExpr = interaction.options.getString("cron", true);
    const message = interaction.options.getString("message", true);
    const rule = await notifyService.createRule({
      guildId: interaction.guildId,
      channelId: channel.id,
      cronExpr,
      message,
    });
    await interaction.reply(`알림 규칙 생성됨: ${rule.id}`);
  },
};
