import mysql from "mysql2/promise";
import "dotenv/config";

const run = async () => {
    const pool = mysql.createPool({
        host: process.env.DB_HOST || "localhost",
        user: process.env.DB_USER || "root",
        password: process.env.DB_PASSWORD,
        database: process.env.DB_NAME || "roadrentals"
    });

    try {
        console.log("Creating Leads table...");
        
        await pool.execute(`
            CREATE TABLE IF NOT EXISTS Leads (
                id INT AUTO_INCREMENT PRIMARY KEY,
                name VARCHAR(100) NOT NULL,
                mobile_number VARCHAR(15) NOT NULL,
                trip_type VARCHAR(50),
                pickup_location TEXT,
                drop_location TEXT,
                created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
            )
        `);
        
        console.log("Leads table successfully created!");
    } catch (e) {
        console.error("Error creating table:", e.message);
    } finally {
        await pool.end();
    }
};

run();
