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

const deleteAllTickets = async () => {
  try {
    console.log('🗑️  Suppression de tous les tickets...\n');

    // Compter les tickets avant suppression
    const countResult = await pool.query('SELECT COUNT(*) as count FROM tickets');
    const totalTickets = parseInt(countResult.rows[0].count);

    if (totalTickets === 0) {
      console.log('ℹ️  Aucun ticket à supprimer. La table est déjà vide.\n');
      process.exit(0);
    }

    console.log(`📊 Nombre de tickets trouvés: ${totalTickets}`);
    console.log('⚠️  Suppression en cours...\n');

    // Supprimer tous les tickets
    const deleteResult = await pool.query('DELETE FROM tickets');

    console.log('✅ Suppression terminée!\n');
    console.log('═══════════════════════════════════════════════════');
    console.log(`🗑️  ${totalTickets} ticket(s) supprimé(s)`);
    console.log('═══════════════════════════════════════════════════\n');

    process.exit(0);
  } catch (error) {
    console.error('❌ Erreur lors de la suppression:', error.message);
    process.exit(1);
  }
};

deleteAllTickets();
