<?php

declare(strict_types=1);

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

use App\Framework\Core\PathProvider;
use App\Framework\DateTime\SystemClock;
use App\Framework\Discovery\UnifiedDiscoveryService;

echo "\nManual Discovery Test (NO CACHE)\n";
echo str_repeat('=', 70) . "\n\n";

// 1. Create PathProvider
$basePath = dirname(__DIR__, 2);
$pathProvider = new PathProvider($basePath);
$clock = new SystemClock();

echo "Source path: " . $pathProvider->getSourcePath() . "\n\n";

// 2. Create Discovery Service
echo "Creating UnifiedDiscoveryService...\n";

// Since UnifiedDiscoveryService requires full container bootstrap, we can't easily test it
// Let's just verify the files manually

echo "Manual File Scan for DataProvider Attributes:\n\n";

$dir = $pathProvider->getSourcePath() . '/Application/LiveComponents/Services';
$files = glob($dir . '/*.php');

$foundProviders = [];

foreach ($files as $file) {
    $content = file_get_contents($file);

    if (preg_match('/#\[DataProvider\s*\(\s*name:\s*[\'"](\w+)[\'"]\s*\)\]/', $content, $matches)) {
        $providerName = $matches[1];

        // Extract class name
        if (preg_match('/class\s+(\w+)/', $content, $classMatches)) {
            $className = $classMatches[1];

            $foundProviders[] = [
                'file' => basename($file),
                'class' => $className,
                'name' => $providerName,
            ];

            echo "✓ Found: {$className} with name '{$providerName}'\n";
        }
    }
}

echo "\n";
echo "Total DataProviders found: " . count($foundProviders) . "\n\n";

if (count($foundProviders) === 0) {
    echo "✗ No DataProviders found - files may not have correct attribute syntax\n";
    exit(1);
}

echo "Summary:\n";
foreach ($foundProviders as $provider) {
    echo "  - {$provider['class']} (name: '{$provider['name']}')\n";
}

echo "\n";
echo "If manual scan finds providers but Discovery doesn't,\n";
echo "the problem is in Discovery's file scanning or caching logic.\n";
