<?php

declare(strict_types=1);

namespace App\Framework\View\Loading;

use App\Framework\View\Exceptions\TemplateNotFoundException;

final readonly class TemplatePathResolver
{
    public function __construct(
        private array $resolvers = []
    ) {
    }

    public function resolve(string $template, ?string $controllerClass = null): string
    {
        foreach ($this->resolvers as $resolver) {
            if ($path = $resolver->resolve($template, $controllerClass)) {
                return $path;
            }
        }

        throw new TemplateNotFoundException($template, $controllerClass ?? '');
    }
}
