"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 viewDatabase() {
    console.log('\n📊 ZEOCRM Database Viewer\n');
    console.log('='.repeat(60));
    try {
        // Count records in each table
        const leadsCount = await db_1.db.select().from(schema_1.leads);
        const usersCount = await db_1.db.select().from(schema_1.users);
        const activitiesCount = await db_1.db.select().from(schema_1.activities);
        const tasksCount = await db_1.db.select().from(schema_1.tasks);
        const notificationsCount = await db_1.db.select().from(schema_1.notifications);
        console.log('\n📈 Table Counts:');
        console.log(`  Leads: ${leadsCount.length}`);
        console.log(`  Users: ${usersCount.length}`);
        console.log(`  Activities: ${activitiesCount.length}`);
        console.log(`  Tasks: ${tasksCount.length}`);
        console.log(`  Notifications: ${notificationsCount.length}`);
        // Show recent activities
        console.log('\n🔄 Recent Activities (last 10):');
        const recentActivities = await db_1.db.select().from(schema_1.activities).orderBy((0, drizzle_orm_1.desc)(schema_1.activities.createdAt)).limit(10);
        recentActivities.forEach((activity, idx) => {
            console.log(`  ${idx + 1}. [${activity.type}] ${activity.description?.substring(0, 50)}... (${activity.createdAt})`);
        });
        // Show users
        console.log('\n👥 Users:');
        usersCount.forEach((user, idx) => {
            console.log(`  ${idx + 1}. ${user.name} (${user.email}) - Role: ${user.role}`);
        });
        // Show lead status breakdown
        console.log('\n📋 Lead Status Breakdown:');
        const statusCounts = {};
        leadsCount.forEach(lead => {
            statusCounts[lead.status] = (statusCounts[lead.status] || 0) + 1;
        });
        Object.entries(statusCounts).forEach(([status, count]) => {
            console.log(`  ${status}: ${count}`);
        });
        console.log('\n' + '='.repeat(60));
        console.log('✅ Database query completed successfully!\n');
    }
    catch (error) {
        console.error('❌ Error querying database:', error);
    }
    process.exit(0);
}
viewDatabase();
