import { drizzle } from 'drizzle-orm/mysql2';
import { inscriptions, sequences, apprenants } from './drizzle/schema.js';
import { eq, and } from 'drizzle-orm';

const db = drizzle(process.env.DATABASE_URL);

console.log('=== Vérification des inscriptions pour formationId=1 ===\n');

// Vérifier toutes les inscriptions
const allInscriptions = await db
  .select({
    inscriptionId: inscriptions.id,
    apprenantId: inscriptions.apprenantId,
    sequenceId: inscriptions.sequenceId,
    statut: inscriptions.statut,
    sequenceNom: sequences.nom,
    formationId: sequences.formationId,
    apprenantNom: apprenants.nom,
    apprenantPrenom: apprenants.prenom,
  })
  .from(inscriptions)
  .innerJoin(sequences, eq(inscriptions.sequenceId, sequences.id))
  .innerJoin(apprenants, eq(inscriptions.apprenantId, apprenants.id))
  .where(eq(sequences.formationId, 1));

console.log(`Total inscriptions trouvées: ${allInscriptions.length}\n`);

allInscriptions.forEach(i => {
  console.log(`- ${i.apprenantPrenom} ${i.apprenantNom} | Séquence: ${i.sequenceNom} | Statut: ${i.statut}`);
});

console.log('\n=== Inscriptions confirmées uniquement ===\n');

const confirmedInscriptions = allInscriptions.filter(i => i.statut === 'confirmee');
console.log(`Total confirmées: ${confirmedInscriptions.length}\n`);

confirmedInscriptions.forEach(i => {
  console.log(`- ${i.apprenantPrenom} ${i.apprenantNom} | Séquence: ${i.sequenceNom}`);
});

process.exit(0);
