<?php declare(strict_types=1);

namespace App\Engine\Home\AboutUs;

final readonly class HomeAboutUsSectionProvider
{

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

    public function __construct(
        private \App\Engine\Settings\Sections\Content\HomeAboutUsSettingsSection $homeAboutUsSettingsSection,
        private \Symfony\Contracts\Cache\CacheInterface                          $fileAdapterCache,
    ) {
    }

    public function provideCached(): \App\Engine\Inertia\Frontend\ViewModels\HomeAboutUsSectionViewModel
    {
        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\Frontend\ViewModels\HomeAboutUsSectionViewModel
    {
        $abouUs = $this->homeAboutUsSettingsSection->get();
        return new \App\Engine\Inertia\Frontend\ViewModels\HomeAboutUsSectionViewModel(
            image: \App\Engine\Thumbnail\Thumbnail::create()
                ->fromRelativePath($abouUs->image)
                ->height(698)
                ->width(1245)
                ->sizeOperation(\App\Engine\Thumbnail\SizeOperation::COVER)
                ->getPictureHtmlTag(),
            title: $abouUs->title,
            text: $abouUs->text,
            link: $abouUs->link,
        );
    }

}