require('dotenv').config();
const mysql = require('mysql2/promise');

const dbConfig = {
    host: process.env.DB_HOST || 'localhost',
    user: process.env.DB_USER || 'root',
    password: process.env.DB_PASSWORD || '',
    database: process.env.DB_NAME || 'masm_app'
};

async function verifyColumns() {
    let connection;
    try {
        connection = await mysql.createConnection(dbConfig);
        
        const [columns] = await connection.query(`
            SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_TYPE
            FROM INFORMATION_SCHEMA.COLUMNS 
            WHERE TABLE_SCHEMA = ? 
            AND TABLE_NAME = 'ambulance_requests'
            AND COLUMN_NAME IN ('latitude', 'longitude', 'destination_latitude', 'destination_longitude')
            ORDER BY ORDINAL_POSITION
        `, [dbConfig.database]);

        console.log('\n📍 Ambulance Requests - Location Columns:');
        console.log('─'.repeat(60));
        columns.forEach(col => {
            console.log(`  ${col.COLUMN_NAME.padEnd(25)} ${col.COLUMN_TYPE.padEnd(20)} ${col.IS_NULLABLE === 'YES' ? 'NULL' : 'NOT NULL'}`);
        });
        console.log('─'.repeat(60));
        console.log(`\n✓ Found ${columns.length} location-related columns\n`);

    } catch (error) {
        console.error('Error:', error.message);
    } finally {
        if (connection) await connection.end();
    }
}

verifyColumns();

