const { Pool } = require('pg');
require('dotenv').config();

const pool = new Pool({
    user: process.env.DB_USER,
    host: process.env.DB_HOST,
    database: process.env.DB_NAME,
    password: process.env.DB_PASSWORD,
    port: process.env.DB_PORT,
});

async function updateCarStatuses() {
    try {
        console.log('Updating car statuses based on active bookings...');

        // 1. Mark cars with confirmed or pending bookings as 'reserved'
        // Car 1 (Bond), Car 2 (Dom), Car 3 (Martin), Car 8 (Tony)
        await pool.query(`
      UPDATE cars
      SET status = 'reserved'
      WHERE id IN (1, 2, 3, 8)
    `);

        // 2. Ensure car 4 (Natasha - Cancelled) is available
        await pool.query(`
      UPDATE cars
      SET status = 'available'
      WHERE id = 4
    `);

        // 3. Mark car 9 (Raj - Pending) as 'reserved' as well
        await pool.query(`
      UPDATE cars
      SET status = 'reserved'
      WHERE id = 9
    `);

        console.log('Car statuses updated successfully!');
    } catch (err) {
        console.error('Error updating car statuses:', err);
    } finally {
        await pool.end();
    }
}

updateCarStatuses();
