<?php

declare(strict_types=1);

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

use App\Framework\Cache\CacheInitializer;
use App\Framework\DI\DefaultContainer;
use App\Framework\Performance\Contracts\PerformanceCollectorInterface;
use App\Framework\Performance\EnhancedPerformanceCollector;

echo "=== Testing Specific Initializer Execution ===\n\n";

try {
    $container = new DefaultContainer();

    // Create a basic PerformanceCollector for testing
    $performanceCollector = new EnhancedPerformanceCollector();
    $container->instance(PerformanceCollectorInterface::class, $performanceCollector);

    echo "Testing CacheInitializer directly...\n";

    // Test if we can create and invoke CacheInitializer directly
    $cacheInitializer = new CacheInitializer($performanceCollector, $container);

    echo "✅ CacheInitializer instantiated successfully\n";

    // Test invocation
    $cacheService = $cacheInitializer();

    echo "✅ CacheInitializer executed successfully\n";
    echo "Cache service type: " . get_class($cacheService) . "\n\n";

    // Test if it works via container invoker
    echo "Testing via container invoker...\n";

    $invokerResult = $container->invoker->invoke(
        \App\Framework\Core\ValueObjects\ClassName::create(CacheInitializer::class),
        '__invoke'
    );

    echo "✅ Container invoker executed successfully\n";
    echo "Invoker result type: " . get_class($invokerResult) . "\n\n";

    // Test if both results are the same
    echo "Are results identical? " . ($cacheService === $invokerResult ? "Yes" : "No") . "\n";
    echo "Are results equal? " . (get_class($cacheService) === get_class($invokerResult) ? "Yes" : "No") . "\n";

} catch (Exception $e) {
    echo "❌ Error: " . $e->getMessage() . "\n";
    echo "Stack trace:\n" . $e->getTraceAsString() . "\n";
}
