"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 deleteBrokenLeads() {
    console.log('🔍 Finding and deleting 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);
        }
        // Delete broken leads
        await db_1.db.delete(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(`✅ Successfully deleted ${brokenLeads.length} broken lead(s)!`);
        console.log('   Your database is now clean.\n');
    }
    catch (error) {
        console.error('❌ Error:', error);
    }
    process.exit(0);
}
deleteBrokenLeads();
