/**
 * Test Zone Search Logic
 */

const mongoose = require('mongoose');
const dotenv = require('dotenv');
const path = require('path');

dotenv.config({ path: path.join(__dirname, '../../.env') });
const bookingService = require('../services/booking.service');

const MONGO_URI = process.env.MONGODB_URI || process.env.MONGO_URI || 'mongodb://localhost:27017/cab-booking';

async function testSearch() {
    try {
        await mongoose.connect(MONGO_URI);
        console.log('Connected to MongoDB');

        // Test Cases
        const testCases = [
            { name: 'Bhopal (MP)', lat: 23.2330, lng: 77.4346, expectedZone: 'Madhya Pradesh Zone' },
            { name: 'Delhi (CP)', lat: 28.6139, lng: 77.2090, expectedZone: 'Delhi NCR Zone' },
            { name: 'Mumbai (Bandra)', lat: 19.0596, lng: 72.8295, expectedZone: 'Mumbai Zone' },
            { name: 'Bangalore (No Zone)', lat: 12.9716, lng: 77.5946, expectedZone: null }
        ];

        for (const test of testCases) {
            console.log(`Searching for ${test.name}...`);
            const result = await bookingService.searchCab({
                pickup: { lat: test.lat, lng: test.lng },
                drop: { lat: test.lat + 0.01, lng: test.lng + 0.01 },
                distance: 10,
                tripType: 'oneWay',
                fuelType: 'petrol'
            });

            const foundZone = result.zone;
            const expectedStr = test.expectedZone || 'null';
            const foundStr = foundZone || 'null';

            if (foundZone === test.expectedZone) {
                console.log(`PASS: Expected ${expectedStr}, Got ${foundStr}`);
            } else {
                console.log(`FAIL: Expected ${expectedStr}, Got ${foundStr}`);
            }
        }

        process.exit(0);
    } catch (error) {
        console.error('Test Failed:', error.message);
        process.exit(1);
    }
}

testSearch();
