<?php
/**
 * Migration Runner - Update billing_cycle to support multi-month options
 * Access this file in your browser: http://localhost/TellerPro/run_billing_cycle_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>Billing Cycle 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; }
    </style>
</head>
<body>
    <h1>Billing Cycle Migration</h1>';

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

    // Modify billing_cycle column to support more options
    $sql = "
        ALTER TABLE subscriptions 
        MODIFY COLUMN billing_cycle ENUM('monthly','3months','6months','yearly') DEFAULT 'monthly'
    ";

    db()->exec($sql);
    echo '<p class="success">✓ Updated billing_cycle column to support multi-month options</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>';
