<?php

declare(strict_types=1);

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

use App\Application\Media\ShowImage;
use App\Framework\Attributes\Route;

echo "=== Manual Attribute Test ===\n";

try {
    // Check if ShowImage class exists
    if (! class_exists(ShowImage::class)) {
        echo "❌ ShowImage class not found!\n";
        exit(1);
    }

    echo "✅ ShowImage class found: " . ShowImage::class . "\n";

    // Get reflection class
    $reflection = new ReflectionClass(ShowImage::class);
    echo "✅ Class reflection created\n";

    // Check methods
    $methods = $reflection->getMethods();
    echo "Methods found: " . count($methods) . "\n";

    foreach ($methods as $method) {
        echo "  Method: " . $method->getName() . "\n";

        // Check for Route attributes
        $attributes = $method->getAttributes(Route::class);
        echo "    Route attributes: " . count($attributes) . "\n";

        foreach ($attributes as $attribute) {
            echo "    *** FOUND Route attribute! ***\n";
            $routeInstance = $attribute->newInstance();
            echo "      Path: " . $routeInstance->path . "\n";
            echo "      Method: " . $routeInstance->method->value . "\n";
        }
    }

    // Check class file location
    $filename = $reflection->getFileName();
    echo "File location: $filename\n";

    // Check if file is in src directory
    if (str_contains($filename, '/src/')) {
        echo "✅ File is in src directory\n";
    } else {
        echo "❌ File is NOT in src directory\n";
    }

    // Check if it should be discovered
    if (str_contains($filename, '/src/Application/')) {
        echo "✅ File is in Application directory - should be discovered\n";
    } else {
        echo "❌ File is NOT in Application directory\n";
    }

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