<?php
/**
 * Migration Runner - Add 'pending' to subscriptions status ENUM
 * Access this file in your browser: http://localhost/TellerPro/run_status_migration.php
 */

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

header('Content-Type: text/html; charset=utf-8');

echo '<!DOCTYPE html>
<html>
<head>
    <title>Running Status Migration</title>
    <style>
        body { font-family: Arial, sans-serif; padding: 20px; max-width: 800px; margin: 0 auto; }
        .success { color: green; }
        .error { color: red; }
        .info { color: blue; }
        pre { background: #f5f5f5; padding: 10px; border-radius: 5px; }
    </style>
</head>
<body>
    <h1>Status Migration</h1>';

try {
    echo '<p class="info">Starting migration...</p>';

    // Modify status column to include 'pending'
    $sql = "
        ALTER TABLE `subscriptions` 
        MODIFY COLUMN `status` ENUM('active','cancelled','expired','past_due','pending') DEFAULT 'active'
    ";
    db()->exec($sql);
    echo '<p class="success">✓ Added "pending" to subscriptions.status ENUM</p>';

    echo '<h2 class="success">Migration completed successfully!</h2>';
    echo '<p><a href="index.php">Return to application</a></p>';

} catch (Exception $e) {
    echo '<h2 class="error">Migration failed</h2>';
    echo '<pre class="error">' . htmlspecialchars($e->getMessage()) . '</pre>';
    echo '<p>Please check your database configuration and try again.</p>';
}

echo '</body>
</html>';
