<?php

declare(strict_types=1);

namespace App\Application\Admin;

use App\Framework\Attributes\Route;
use App\Framework\Auth\Auth;
use App\Framework\Cache\Cache;
use App\Framework\Discovery\Results\DiscoveryRegistry;

final readonly class ShowDiscovery
{
    public function __construct(
        private DiscoveryRegistry $results,
    ) {
    }

    #[Auth]
    #[Route('/admin/discovery')]
    public function show(
        #Cache $cache
    ): void {
        $attributeTypes = $this->results->attributes()->getAllTypes();

        foreach ($attributeTypes as $attributeType) {
            echo "Attribute: $attributeType <br/>";
            echo "<ul>";
            $attributeMappings = $this->results->attributes()->get($attributeType);
            foreach ($attributeMappings as $attributeMapping) {
                $className = $attributeMapping->className->getFullyQualified();
                $methodName = $attributeMapping->methodName?->toString() ?? '';
                echo "<li>" . $className . '::' . $methodName . '()</li>';
            }
            echo "</ul>";
        }

    }
}
