<?php declare(strict_types=1);

namespace App\Engine\VisitorsNotification;

use Doctrine\Bundle\DoctrineBundle\Attribute\AsEntityListener;

#[AsEntityListener(event: \Doctrine\ORM\Events::postPersist, method: "handle", entity: VisitorsNotification::class)]
#[AsEntityListener(event: \Doctrine\ORM\Events::postUpdate, method: "handle", entity: VisitorsNotification::class)]
#[AsEntityListener(event: \Doctrine\ORM\Events::postRemove, method: "handle", entity: VisitorsNotification::class)]
readonly class VisitorsNotificationEntityUpdatedListener
{

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

    public function handle(VisitorsNotification $visitorsNotification, \Doctrine\Persistence\Event\LifecycleEventArgs $args): void
    {
        foreach (LocationEnum::cases() as $case) {
            $this->fileAdapterCache->delete(VisitorsNotificationsProvider::getCacheKey($case));
        }
    }

}