<?php declare(strict_types=1);

namespace App\Engine\Inertia\Providers;

readonly class BrandInformationProvider
{

    public const CACHE_KEY = "BrandInformationsCacheKey";
    public const CACHE_TTL = 3600;

    public function __construct(
        protected \Symfony\Contracts\Cache\CacheInterface            $fileAdapterCache,
        protected \Symfony\Contracts\Translation\TranslatorInterface $translator,
        protected \App\Engine\System\SystemVersion                   $systemVersion,
    ) {
    }

    public function provideCached(): \App\Engine\Inertia\ViewModels\BrandInformationViewModel
    {
        return $this->fileAdapterCache->get(self::CACHE_KEY, function (\Symfony\Component\Cache\CacheItem $item) {
            $item->expiresAfter(self::CACHE_TTL);
            return $this->provide();
        });
    }

    public function provide(): \App\Engine\Inertia\ViewModels\BrandInformationViewModel
    {
        $shortHash = exec("git rev-parse --short HEAD");

        $viewModel = new \App\Engine\Inertia\ViewModels\BrandInformationViewModel();
        $viewModel->productName = "IntelliFLEX";
        $viewModel->productType = "PRO";
        $viewModel->productVersion = $this->systemVersion->getVersion();
        $viewModel->productHash = $shortHash ?: $this->translator->trans("admin.brand-information.unable-to-load-git-hash");

        return $viewModel;
    }

}