<?php

declare(strict_types=1);

namespace App\Framework\Router;

final readonly class CompiledPattern
{
    /**
     * @param string $regex Primary regex (for backward compatibility)
     * @param array<int, RouteData> $routes Compiled route data objects
     * @param array<string, array{regex: string, routes: array<mixed>}> $batches Optimized route batches
     */
    public function __construct(
        public string $regex,
        public array $routes,
        public array $batches = []
    ) {
    }

    public function getRouteData(int $routeIndex): RouteData
    {
        return $this->routes[$routeIndex];
    }

    /**
     * Get routes grouped by complexity for optimized matching
     * @return array<string, array{regex: string, routes: array<mixed>}>
     */
    public function getBatches(): array
    {
        return $this->batches;
    }

    /**
     * Check if this pattern uses optimized batches
     */
    public function hasOptimizedBatches(): bool
    {
        return ! empty($this->batches);
    }
}
