import { Events } from 'discord.js';
import { db } from '../core/db.js';

export default {
  name: Events.ClientReady,
  once: true,
  execute(client) {
    console.log(`🤖 Logged in as ${client.user.tag} (${client.user.id})`);
    // Sync all current guilds to DB so dashboard sees them
    const stmt = db.prepare(`
      INSERT INTO guilds (guild_id, name, owner_id) VALUES (?, ?, ?)
      ON CONFLICT(guild_id) DO UPDATE SET name = excluded.name
    `);
    let synced = 0;
    for (const [, g] of client.guilds.cache) {
      stmt.run(g.id, g.name, g.ownerId);
      synced++;
    }
    if (synced) console.log(`📡 Synced ${synced} guild(s) to dashboard`);

    client.user.setPresence({
      activities: [{ name: '/help · powered by haikz', type: 0 }],
      status: 'online',
    });
  },
};
