<?php declare(strict_types=1);

namespace App\Engine\Inertia\Frontend\GeneralContacts;

final readonly class GeneralContactsProvider
{

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

    public function __construct(
        private readonly \App\Engine\Settings\Sections\Contact\GeneralContactsSettingsSection $generalContactsSettingsSection,
        private \Symfony\Contracts\Cache\CacheInterface                                       $fileAdapterCache,
    ) {
    }

    public function provideCached(): \App\Engine\Inertia\Frontend\ViewModels\GeneralContactsViewModel
    {
        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\GeneralContactsViewModel
    {
        $generalContacts = $this->generalContactsSettingsSection->get();

        return new \App\Engine\Inertia\Frontend\ViewModels\GeneralContactsViewModel(
            address: $generalContacts->address,
            country: $generalContacts->country,
            phone: $generalContacts->phone,
            mapLink: $generalContacts->mapLink,
            socialsFacebookLink: $generalContacts->socialsFacebookLink,
            socialsInstagramLink: $generalContacts->socialsInstagramLink,
        );
    }

}