import mongoose from 'mongoose';
import Event from '../server/models/event.js';

const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://localhost:27017/ghostguild';

async function listAll() {
  try {
    await mongoose.connect(MONGODB_URI);
    
    // Group events by series ID
    const allEvents = await Event.find({ 'series.isSeriesEvent': true })
      .select('title series.id')
      .sort({ 'series.id': 1, 'series.position': 1 })
      .lean();
    
    const grouped = {};
    allEvents.forEach(e => {
      const sid = e.series?.id || 'unknown';
      if (!grouped[sid]) grouped[sid] = [];
      grouped[sid].push(e.title);
    });
    
    console.log('Events grouped by series.id:\n');
    Object.entries(grouped).forEach(([sid, events]) => {
      console.log(`${sid} (${events.length} events):`);
      events.forEach(e => console.log(`  - ${e}`));
      console.log('');
    });
    
  } catch (error) {
    console.error('Error:', error);
  } finally {
    await mongoose.connection.close();
  }
}

listAll();
