<?php
/**
 * Migration: Add suspended status to sales table
 * Run this script to update your database schema for POS suspend feature
 */

require_once __DIR__ . '/../config/database.php';

echo "Adding suspended status to database...\n";

try {
    // Modify status column to include suspended
    $sql = "
        ALTER TABLE sales 
        MODIFY COLUMN status ENUM('suspended','completed','cancelled','refunded') DEFAULT 'completed'
    ";

    db()->exec($sql);
    echo "Added 'suspended' to sales.status\n";

    // Add suspended_at column
    try {
        $sql = "
            ALTER TABLE sales
            ADD COLUMN suspended_at TIMESTAMP NULL AFTER created_at
        ";
        db()->exec($sql);
        echo "Added suspended_at column to sales table\n";
    } catch (Exception $e) {
        // Column might already exist
        if (strpos($e->getMessage(), 'duplicate column') !== false) {
            echo "suspended_at column already exists\n";
        } else {
            throw $e;
        }
    }

    echo "Migration completed successfully!\n";

} catch (Exception $e) {
    echo "Migration failed: " . $e->getMessage() . "\n";
    exit(1);
}
