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

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

async function diagnose() {
  try {
    await mongoose.connect(MONGODB_URI);
    
    console.log('Query 1: Find with series.id AND series.isSeriesEvent');
    const events1 = await Event.find({ 
      'series.id': 'cooperative-values-into-practice',
      'series.isSeriesEvent': true
    }).select('title series').lean();
    console.log(`  Found: ${events1.length} events`);
    events1.forEach(e => console.log(`    - ${e.title} (isSeriesEvent: ${e.series?.isSeriesEvent})`));
    
    console.log('\nQuery 2: Find with just series.id');
    const events2 = await Event.find({ 
      'series.id': 'cooperative-values-into-practice'
    }).select('title series').lean();
    console.log(`  Found: ${events2.length} events`);
    events2.forEach(e => console.log(`    - ${e.title} (isSeriesEvent: ${e.series?.isSeriesEvent})`));
    
    console.log('\nChecking one Module event directly:');
    const module0 = await Event.findOne({ title: 'Module 0: Orientation' }).select('series').lean();
    if (module0) {
      console.log(`  series.id: "${module0.series?.id}"`);
      console.log(`  series.isSeriesEvent: ${module0.series?.isSeriesEvent}`);
      console.log(`  series.title: "${module0.series?.title}"`);
    } else {
      console.log('  NOT FOUND');
    }
    
  } catch (error) {
    console.error('Error:', error);
  } finally {
    await mongoose.connection.close();
  }
}

diagnose();
