require('dotenv').config();
const db = require('../config/database');

const testData = {
    request_by: 4,
    is_urgent: 0,
    location: 'Current Location',
    destination: 'Lilongwe: Likuni',
    latitude: -13.9610416,
    longitude: 33.7940749,
    destination_latitude: -14.0281706,
    destination_longitude: 33.7066948,
    status: 'pending'
};

const { request_by, is_urgent, location, destination, latitude, longitude, destination_latitude, destination_longitude, status } = testData;

const query = `INSERT INTO ambulance_requests 
    (request_by, is_urgent, location, destination, latitude, longitude, destination_latitude, destination_longitude, status) 
    VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`;

const params = [
    request_by, 
    is_urgent || false, 
    location, 
    destination || null, 
    latitude, 
    longitude,
    destination_latitude || null,
    destination_longitude || null,
    status || 'pending'
];

console.log('Query:', query);
console.log('Parameters:', params);
console.log('Parameter count:', params.length);

db.query(query, params, (err, results) => {
    if (err) {
        console.error('Error:', err.message);
        console.error('Full error:', err);
    } else {
        console.log('Success! Insert ID:', results.insertId);
        
        // Verify the insert
        db.query('SELECT * FROM ambulance_requests WHERE id = ?', [results.insertId], (err, rows) => {
            if (err) {
                console.error('Error fetching:', err);
            } else {
                console.log('\nInserted record:');
                console.log(JSON.stringify(rows[0], null, 2));
            }
            process.exit(0);
        });
    }
});

