"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const db_1 = require("../db");
const schema_1 = require("../db/schema");
const drizzle_orm_1 = require("drizzle-orm");
async function fixBrokenLeads() {
    console.log('🔍 Searching for leads without IDs...\n');
    try {
        // Find leads with null or empty IDs
        const brokenLeads = await db_1.db.select().from(schema_1.leads).where((0, drizzle_orm_1.or)((0, drizzle_orm_1.isNull)(schema_1.leads.id), (0, drizzle_orm_1.eq)(schema_1.leads.id, '')));
        console.log(`Found ${brokenLeads.length} broken lead(s)\n`);
        if (brokenLeads.length === 0) {
            console.log('✅ No broken leads found! Database is healthy.');
            process.exit(0);
        }
        // Display broken leads
        brokenLeads.forEach((lead, idx) => {
            console.log(`${idx + 1}. Lead:`);
            console.log(`   Customer: ${lead.customerName || 'N/A'}`);
            console.log(`   Destination: ${lead.destination || 'N/A'}`);
            console.log(`   Status: ${lead.status || 'N/A'}`);
            console.log(`   ID: ${lead.id || 'MISSING'}`);
            console.log('');
        });
        console.log('⚠️  These leads need to be deleted manually from the database viewer.');
        console.log('   Go to /database and remove them from the Leads table.\n');
    }
    catch (error) {
        console.error('❌ Error:', error);
    }
    process.exit(0);
}
fixBrokenLeads();
