<?php
require_once 'd:/xampp/htdocs/shopnest/php-api-server/config/database.php';
$db = getDb();

$expectedColumns = [
    'user_id'              => "INT NOT NULL",
    'total_price'          => "DECIMAL(10,2) NOT NULL",
    'status'               => "VARCHAR(50) DEFAULT 'Pending'",
    'shipping_address'     => "TEXT",
    'special_instructions' => "TEXT",
    'start_date'           => "DATE",
    'return_date'          => "DATE",
    'rental_days'          => "INT DEFAULT 3",
    'payment_status'       => "VARCHAR(50) DEFAULT 'Pending'",
    'payment_method'       => "VARCHAR(50) DEFAULT 'cod'",
    'payment_id'           => "VARCHAR(100)",
    'razorpay_order_id'    => "VARCHAR(255)",
    'created_at'           => "TIMESTAMP DEFAULT CURRENT_TIMESTAMP"
];

foreach ($expectedColumns as $column => $definition) {
    try {
        $res = $db->query("SHOW COLUMNS FROM orders LIKE '$column'");
        if ($res->num_rows === 0) {
            $db->query("ALTER TABLE orders ADD `$column` $definition");
            echo "Added column: $column\n";
        } else {
            // Optionally modify existing column if needed
            // $db->query("ALTER TABLE orders MODIFY `$column` $definition");
            // echo "Verified column: $column\n";
        }
    } catch (Exception $e) {
        echo "Error with column $column: " . $e->getMessage() . "\n";
    }
}

echo "\nOrders table unified.\n";
