#!/usr/bin/env node
/**
 * Add /delserver documentation to #staff-commands
 * 
 * Created: April 8, 2026
 * Chronicler: #71
 */

require('dotenv').config({ path: '/opt/arbiter-3.0/.env' });
const { Client, GatewayIntentBits, ChannelType, EmbedBuilder } = require('discord.js');

async function main() {
  console.log('📋 Adding /delserver to #staff-commands');
  console.log('=======================================');

  const client = new Client({ 
    intents: [GatewayIntentBits.Guilds] 
  });

  try {
    await client.login(process.env.DISCORD_BOT_TOKEN);
    await new Promise(resolve => {
      if (client.isReady()) resolve();
      else client.once('ready', resolve);
    });
    console.log(`✅ Logged in as ${client.user.tag}`);

    const guild = client.guilds.cache.get(process.env.GUILD_ID);
    await guild.channels.fetch();

    // Find #staff-commands
    const channel = guild.channels.cache.find(
      ch => ch.name === 'staff-commands'
    );

    if (!channel) {
      console.log('❌ #staff-commands not found!');
      return;
    }
    console.log(`✅ Found: #${channel.name}`);

    // /delserver command embed
    const delServerEmbed = new EmbedBuilder()
      .setColor(0xDC3545) // Red for danger/delete
      .setTitle('🗑️ /delserver')
      .setDescription('Permanently deletes a server setup including all channels and the role.')
      .addFields(
        { 
          name: '👥 Who Can Use', 
          value: 'Staff, Moderators, Trinity only', 
          inline: true 
        },
        { 
          name: '📍 Where to Use', 
          value: 'Any channel', 
          inline: true 
        },
        {
          name: '📝 Usage',
          value: '```/delserver name:Server Name confirm:True```',
          inline: false
        },
        {
          name: '⚠️ Preview Mode',
          value: `Running without \`confirm:True\` shows a preview:
\`\`\`/delserver name:Server Name\`\`\`
This lists what would be deleted without actually deleting anything.`,
          inline: false
        },
        {
          name: '🗑️ What It Deletes',
          value: `• All channels in the category (chat, in-game, forum, voice)
• The category itself
• The server role`,
          inline: false
        },
        {
          name: '📋 After Running',
          value: `Don't forget to:

1. Remove the reaction emoji from <#1403980899464384572>
2. Remove the role mapping from Carl-bot`,
          inline: false
        },
        {
          name: '💡 Notes',
          value: `• Always preview first before confirming
• Give players at least 7 days notice before deleting
• This is permanent — there is no undo
• Forum posts and messages are lost forever`,
          inline: false
        }
      )
      .setFooter({ text: 'The Arbiter • Firefrost Gaming' });

    await channel.send({ embeds: [delServerEmbed] });
    console.log('✅ Posted /delserver documentation');

    console.log('');
    console.log('✅ Done! Don\'t forget to pin it.');

  } catch (error) {
    console.error('❌ ERROR:', error.message);
  } finally {
    client.destroy();
  }
}

main();
