<?php

declare(strict_types=1);

// Bootstrap the application
require_once __DIR__ . '/../../vendor/autoload.php';

use App\Framework\Core\AppBootstrapper;
use App\Framework\DI\Initializer;
use App\Framework\Discovery\Results\DiscoveryRegistry;
use App\Framework\Performance\MemoryMonitor;
use App\Framework\Performance\PerformanceCollector;

$basePath = __DIR__ . '/../..';

// Create performance collector
$collector = new PerformanceCollector();
$memoryMonitor = new MemoryMonitor();

// Bootstrap application
$bootstrapper = new AppBootstrapper($basePath, $collector, $memoryMonitor);
$container = $bootstrapper->bootstrapWorker();

// Get discovery registry
$registry = $container->get(DiscoveryRegistry::class);

// Find all Initializer attributes
$initializers = $registry->attributes->get(Initializer::class);

echo "Found " . count($initializers) . " Initializer attributes:\n\n";

foreach ($initializers as $discoveredAttribute) {
    $className = $discoveredAttribute->className->toString();
    $methodName = $discoveredAttribute->methodName?->toString() ?? 'N/A';

    // Check if it's RequestFactory
    if (str_contains($className, 'RequestFactory')) {
        echo ">>> FOUND RequestFactory!\n";
        echo "Class: {$className}\n";
        echo "Method: {$methodName}\n";

        // Check additional data
        $additionalData = $discoveredAttribute->additionalData;
        if ($additionalData) {
            echo "Additional Data:\n";
            print_r($additionalData);
        }
        echo "\n";
    }

    echo "{$className}::{$methodName}\n";
}

echo "\nChecking Container bindings for Request interface...\n";
if ($container->has(\App\Framework\Http\Request::class)) {
    echo "✅ Request interface IS bound\n";
} else {
    echo "❌ Request interface is NOT bound\n";
}
