<?php declare(strict_types=1);

namespace App\Engine\UpcomingEvent;

use Doctrine\Bundle\DoctrineBundle\Attribute\AsEntityListener;

#[AsEntityListener(event: \Doctrine\ORM\Events::postPersist, method: "handle", entity: \App\Engine\UpcomingEvent\UpcomingEvent::class)]
#[AsEntityListener(event: \Doctrine\ORM\Events::postUpdate, method: "handle", entity: \App\Engine\UpcomingEvent\UpcomingEvent::class)]
#[AsEntityListener(event: \Doctrine\ORM\Events::postRemove, method: "handle", entity: \App\Engine\UpcomingEvent\UpcomingEvent::class)]
readonly class UpcomingEventEntityUpdatedListener
{

    public function __construct(
        private \Symfony\Contracts\Cache\CacheInterface $fileAdapterCache,
    ) {
    }

    public function handle(\App\Engine\UpcomingEvent\UpcomingEvent $upcomingEvent, \Doctrine\Persistence\Event\LifecycleEventArgs $args): void
    {
        $this->fileAdapterCache->delete(UpcomingEventProvider::HOMEPAGE_CACHE_KEY);
        $this->fileAdapterCache->delete(UpcomingEventProvider::LIST_CACHE_KEY);
        $this->fileAdapterCache->delete(UpcomingEventProvider::ARCHIVE_CACHE_KEY);
    }

}