<?php declare(strict_types=1);

namespace App\Engine\Literature;

use Doctrine\Bundle\DoctrineBundle\Attribute\AsEntityListener;

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

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

    public function handle(\App\Engine\Literature\Literature $literature, \Doctrine\Persistence\Event\LifecycleEventArgs $args): void
    {
        $this->fileAdapterCache->delete(LiteratureProvider::getCacheKey());
    }

}