<?php

declare(strict_types=1);

namespace App\Framework\View;

use App\Framework\DI\Container;
use App\Framework\View\Functions\TemplateFunction;

final readonly class TemplateFunctions
{
    private array $functions;

    public function __construct(
        private Container $container,
        string ...$templateFunctions
    ) {
        $functions = [];
        foreach ($templateFunctions as $function) {
            $functionInstance = $this->container->get($function);
            $functions[$functionInstance->functionName] = $functionInstance;
        }
        $this->functions = $functions;
    }

    public function has(string $functionName): bool
    {
        return isset($this->functions[$functionName]);
    }

    public function get(string $functionName): ?TemplateFunction
    {
        return $this->functions[$functionName] ?? null;
    }
}
