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

$columnsToAdd = [
    'payment_method'       => "VARCHAR(50) DEFAULT 'cod' AFTER payment_status",
    'razorpay_order_id'    => "VARCHAR(255) AFTER payment_method",
    'payment_id'           => "VARCHAR(100) AFTER razorpay_order_id",
    'special_instructions' => "TEXT AFTER shipping_address",
    'start_date'           => "DATE AFTER special_instructions",
    'return_date'          => "DATE AFTER start_date",
    'rental_days'          => "INT(11) AFTER return_date"
];

foreach ($columnsToAdd as $column => $definition) {
    try {
        // Check if column exists
        $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 {
            echo "Column already exists: $column\n";
        }
    } catch (Exception $e) {
        echo "Error with column $column: " . $e->getMessage() . "\n";
    }
}

echo "\nOrders table updated.\n";
