<?php

declare(strict_types=1);

require_once __DIR__ . '/../bootstrap.php';

// Get test container
$container = createTestContainer();

// Get migration services
$migrationLoader = $container->get(App\Framework\Database\Migration\MigrationLoader::class);
$validator = $container->get(App\Framework\Database\Migration\Services\MigrationValidator::class);
$databaseManager = $container->get(App\Framework\Database\Migration\Services\MigrationDatabaseManager::class);

// Load all migrations
$migrations = $migrationLoader->loadAllMigrations();
$appliedVersions = App\Framework\Database\Migration\MigrationVersionCollection::fromStrings(
    $databaseManager->getAppliedVersions()
);

echo "=== Running Pre-Flight Checks ===\n\n";

// Run pre-flight checks
$results = $validator->runPreFlightChecks($migrations, $appliedVersions);

foreach ($results as $check => $result) {
    echo "Check: {$check}\n";
    echo "  Status: {$result['status']}\n";
    echo "  Message: {$result['message']}\n";
    if (isset($result['severity'])) {
        echo "  Severity: {$result['severity']}\n";
    }
    if (! empty($result['details'])) {
        echo "  Details:\n";
        print_r($result['details']);
    }
    echo "\n";
}

echo "\n=== Dependency Validation ===\n\n";

$depResults = $validator->validateMigrationDependencies($migrations, $appliedVersions);
print_r($depResults);
