<?php

declare(strict_types=1);

namespace App\Framework\Core;

use App\Framework\Router\ValueObjects\ParameterCollection;

final readonly class DynamicRoute implements Route
{
    public function __construct(
        public string $regex,
        public array $paramNames, // ['id', 'userId'] - URL-Parameter-Namen
        public string $controller,
        public string $action,
        public array $parameters,
        public array $paramValues = [], // ['id' => '123', 'userId' => '456'] - URL-Parameter-Werte
        public string $name = '',
        public string $path = '',
        public array $attributes = [],
        public ?ParameterCollection $parameterCollection = null
    ) {
    }

    /**
     * Get type-safe parameter collection (preferred)
     */
    public function getParameterCollection(): ParameterCollection
    {
        if ($this->parameterCollection !== null) {
            return $this->parameterCollection;
        }

        // Fallback: Create ParameterCollection from legacy array
        // This should not happen in production with proper RouteCompiler
        return new ParameterCollection();
    }
}
