<?php

declare(strict_types=1);

namespace App\Framework\View\Loading\Resolvers;

final readonly class TemplateMapResolver implements TemplateResolverStrategy
{
    public const string TEMPLATE_EXTENSION = '.view.php';

    public function __construct(
        private array $templates = []
    ) {
    }

    public function resolve(string $template, ?string $controllerClass = null): ?string
    {
        $key = $template . self::TEMPLATE_EXTENSION;
        $path = $this->templates[$key] ?? null;

        return ($path && file_exists($path)) ? $path : null;
    }
}
