<?php

declare(strict_types=1);

require_once __DIR__ . '/vendor/autoload.php';

use App\Framework\Core\AppBootstrapper;
use App\Framework\Performance\EnhancedPerformanceCollector;
use App\Framework\DateTime\SystemClock;
use App\Framework\DateTime\SystemHighResolutionClock;
use App\Framework\Performance\MemoryMonitor;

echo "Testing Queue Initializer Discovery...\n\n";

try {
    // Create dependencies for enhanced performance collector
    $clock = new SystemClock();
    $highResClock = new SystemHighResolutionClock();
    $memoryMonitor = new MemoryMonitor();
    $collector = new EnhancedPerformanceCollector($clock, $highResClock, $memoryMonitor, enabled: false);

    // Bootstrap the framework
    $bootstrapper = new AppBootstrapper(__DIR__, $collector, $memoryMonitor);
    $container = $bootstrapper->bootstrapWorker();

    echo "Framework bootstrapped successfully.\n";

    // Check if Queue services are available
    $services = [
        'App\Framework\Queue\Interfaces\DistributedLockInterface',
        'App\Framework\Queue\Services\WorkerRegistry',
        'App\Framework\Queue\Services\JobDistributionService',
        'App\Framework\Queue\Services\WorkerHealthCheckService',
        'App\Framework\Queue\Services\FailoverRecoveryService',
        'App\Framework\Queue\Contracts\JobProgressTrackerInterface',
        'App\Framework\Queue\Contracts\DeadLetterQueueInterface',
        'App\Framework\Queue\Services\JobMetricsManagerInterface',
        'App\Framework\Queue\Contracts\JobDependencyManagerInterface'
    ];

    echo "\nChecking Queue service registrations:\n";
    echo str_repeat("=", 50) . "\n";

    foreach ($services as $service) {
        if ($container->has($service)) {
            echo "✅ {$service} - REGISTERED\n";
        } else {
            echo "❌ {$service} - NOT REGISTERED\n";
        }
    }

    echo "\nTotal container bindings: " . count($container->getBindings()) . "\n";

} catch (Throwable $e) {
    echo "Error: " . $e->getMessage() . "\n";
    echo "File: " . $e->getFile() . ":" . $e->getLine() . "\n";
}