const mongoose = require('mongoose');
const dotenv = require('dotenv');
const path = require('path');
dotenv.config({ path: path.resolve(__dirname, '../../.env') });

const Zone = require('../models/zone.model');
const Vehicle = require('../models/vehicle.model');

async function test() {
    await mongoose.connect(process.env.MONGODB_URI);
    console.log('Connected!\n');

    // Show ALL zones
    console.log('=== ALL ZONES ===');
    const zones = await Zone.find({});
    zones.forEach(z => {
        console.log(`  ${z.zoneName} - ID: ${z._id} - Active: ${z.isActive}`);
    });

    // Show ALL vehicles
    console.log('\n=== ALL VEHICLES ===');
    const vehicles = await Vehicle.find({}).populate('zone', 'zoneName');
    vehicles.forEach(v => {
        console.log(`  ${v.registrationNumber} - Zone: ${v.zone?.zoneName} - status: ${v.status} - opStatus: ${v.operationalStatus}`);
    });

    // Find vehicles in MP Zone
    const mpZone = await Zone.findOne({ zoneName: /madhya/i });
    if (mpZone) {
        console.log('\n=== VEHICLES IN MP ZONE ===');
        const mpVehicles = await Vehicle.find({ zone: mpZone._id });
        console.log('Count:', mpVehicles.length);
        mpVehicles.forEach(v => console.log(`  ${v.registrationNumber}`));
    }

    await mongoose.disconnect();
}
test();
