<?php
/**
 * Migration Runner Script
 * تشغيل migrations مرة واحدة فقط
 * 
 * الاستخدام:
 * php scripts/run_migrations.php
 */

require_once __DIR__ . '/../config/config.php';
require_once __DIR__ . '/../src/Core/Database.php';
require_once __DIR__ . '/../src/Core/MigrationRunner.php';
require_once __DIR__ . '/../src/Core/Logger.php';

date_default_timezone_set($config['timezone'] ?? 'UTC');

$logger = new \App\Core\Logger();
$db = \App\Core\Database::getInstance($config['db'])->connection();

echo "=== تشغيل Migrations ===\n\n";

$migrationRunner = new \App\Core\MigrationRunner($db, __DIR__ . '/../migrations');
$results = $migrationRunner->runPendingMigrations();

if (!empty($results['success'])) {
    echo "✅ Migrations المنفذة بنجاح:\n";
    foreach ($results['success'] as $file) {
        echo "   - {$file}\n";
    }
    echo "\n";
}

if (!empty($results['failed'])) {
    echo "❌ Migrations الفاشلة:\n";
    foreach ($results['failed'] as $file) {
        echo "   - {$file}\n";
    }
    echo "\n";
}

if (empty($results['success']) && empty($results['failed'])) {
    echo "ℹ️  لا توجد migrations معلقة.\n";
}

echo "=== انتهى ===\n";
