import { pool } from '../db.js';

async function checkTicketsWithType() {
  try {
    console.log('\n🔍 VÉRIFICATION DES TICKETS AVEC TYPE\n');

    // Exemple de tickets avec le type de prize
    const tickets = await pool.query(`
      SELECT
        t.id,
        t.code,
        t.status,
        t.played_at,
        p.name as prize_name,
        p.type as prize_type,
        p.value as prize_value
      FROM tickets t
      JOIN prizes p ON t.prize_id = p.id
      WHERE t.user_id IS NOT NULL
      LIMIT 10
    `);

    console.log(`Tickets trouvés: ${tickets.rows.length}\n`);

    tickets.rows.forEach((ticket, index) => {
      console.log(`${index + 1}. Code: ${ticket.code}`);
      console.log(`   Lot: ${ticket.prize_name}`);
      console.log(`   Type: ${ticket.prize_type}`);
      console.log(`   Valeur: ${ticket.prize_value}€`);
      console.log(`   Statut: ${ticket.status || 'Non joué'}`);
      console.log(`   Joué: ${ticket.played_at ? new Date(ticket.played_at).toLocaleString('fr-FR') : 'Non'}\n`);
    });

    await pool.end();
    process.exit(0);
  } catch (error) {
    console.error('❌ Erreur:', error.message);
    await pool.end();
    process.exit(1);
  }
}

checkTicketsWithType();
