<?php

declare(strict_types=1);

namespace App\Framework\Discovery\Plugins;

use App\Framework\Discovery\Contracts\DiscoveryPlugin;
use App\Framework\Discovery\Contracts\DiscoveryVisitor;
use App\Framework\Discovery\Results\DiscoveryRegistry;
use App\Framework\Discovery\ValueObjects\DiscoveryContext;
use App\Framework\Discovery\Visitors\RouteVisitor;

/**
 * Plugin for discovering routes
 */
final readonly class RouteDiscoveryPlugin implements DiscoveryPlugin
{
    /** @var array<DiscoveryVisitor> */
    private array $visitors;

    public function __construct()
    {
        $this->visitors = [
            new RouteVisitor(),
        ];
    }

    public function getName(): string
    {
        return 'routes';
    }

    public function initialize(DiscoveryContext $context): void
    {
        foreach ($this->visitors as $visitor) {
            $visitor->reset();
        }
    }

    public function finalize(DiscoveryContext $context, DiscoveryRegistry $registry): void
    {
        // Routes are already in the registry
    }

    public function getVisitors(): array
    {
        return $this->visitors;
    }

    public function isEnabled(DiscoveryContext $context): bool
    {
        // Always enabled for route discovery
        return true;
    }
}
