<?php declare(strict_types=1);

namespace App\Engine\Home\StaticBanners;

use Doctrine\Bundle\DoctrineBundle\Attribute\AsEntityListener;

#[AsEntityListener(event: \Doctrine\ORM\Events::postUpdate, method: "postUpdate", entity: \App\Engine\Settings\Settings::class)]
readonly class SettingsEntityUpdatedListener
{

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

    public function postUpdate(\App\Engine\Settings\Settings $settings, \Doctrine\ORM\Event\PostUpdateEventArgs $args): void
    {
        if ($settings->getId() !== $this->homeStaticBannersSettingsSection->getId()) {
            return;
        }

        $this->fileAdapterCache->delete(HomeStaticBannersSectionProvider::CACHE_KEY);
    }

}