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

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

async function checkVehicles() {
    try {
        await mongoose.connect(process.env.MONGODB_URI);
        console.log('Connected to DB');

        const vehicles = await Vehicle.find({}).populate('zone', 'zoneName')
            .populate('group')
            .populate('category');

        console.log(`\nFound ${vehicles.length} vehicles:\n`);

        vehicles.forEach(v => {
            console.log(`Registration: ${v.registrationNumber}`);
            console.log(`Zone: ${v.zone?.zoneName}`);
            console.log(`Status: ${v.status} / OpStatus: ${v.operationalStatus}`);
            console.log(`Group: ${v.group?.groupName}`);

            // Check fuel pricing
            const fuelPricing = v.group?.fuelPricing || [];
            const fuelTypes = fuelPricing.map(fp => fp.fuelType);
            console.log(`Supported Fuel Types: ${fuelTypes.join(', ')}`);

            console.log('---------------------------');
        });

    } catch (err) {
        console.error(err);
    } finally {
        await mongoose.disconnect();
    }
}

checkVehicles();
