<?php

declare(strict_types=1);

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

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

echo "\nAll Discovered Attributes Debug\n";
echo str_repeat('=', 70) . "\n\n";

// Bootstrap Application
$basePath = dirname(__DIR__, 2);
$clock = new SystemClock();
$highResClock = new SystemHighResolutionClock();
$memoryMonitor = new MemoryMonitor();
$collector = new EnhancedPerformanceCollector($clock, $highResClock, $memoryMonitor, enabled: false);
$bootstrapper = new AppBootstrapper($basePath, $collector, $memoryMonitor);
$app = $bootstrapper->bootstrapConsole();

// Get Container via reflection
$reflection = new ReflectionClass($bootstrapper);
$containerProp = $reflection->getProperty('container');
$containerProp->setAccessible(true);
$container = $containerProp->getValue($bootstrapper);

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

// Get AttributeRegistry
$attributeRegistry = $discoveryRegistry->attributes();

// Use reflection to see internal state
$attrReflection = new ReflectionClass($attributeRegistry);
$attributesProp = $attrReflection->getProperty('attributes');
$attributesProp->setAccessible(true);
$allAttributes = $attributesProp->getValue($attributeRegistry);

echo "Total attribute types discovered: " . count($allAttributes) . "\n\n";

echo "Discovered attribute types:\n";
foreach ($allAttributes as $attributeClass => $discovered) {
    echo "  - {$attributeClass}: " . count($discovered) . " instances\n";
}

echo "\n";

// Check specifically for DataProvider
$dataProviderKey = 'App\\Framework\\LiveComponents\\Attributes\\DataProvider';
if (isset($allAttributes[$dataProviderKey])) {
    echo "✓ DataProvider IS in the registry with " . count($allAttributes[$dataProviderKey]) . " instances\n";
} else {
    echo "✗ DataProvider is NOT in the registry\n";
    echo "  This means Discovery is not configured to scan for this attribute\n";
}
