<?php

declare(strict_types=1);

namespace KupShop\UserBundle\EventListener;

use KupShop\KupShopBundle\Context\PriceLevelContext;
use KupShop\KupShopBundle\Context\UserContext;
use KupShop\KupShopBundle\Util\Contexts;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Http\Event\LogoutEvent;

class UserLogoutListener implements EventSubscriberInterface
{
    private $session;

    public function __construct(SessionInterface $session)
    {
        $this->session = $session;
    }

    public static function getSubscribedEvents()
    {
        return [
            LogoutEvent::class => [
                ['userLogout', 200],
            ],
        ];
    }

    public function userLogout(LogoutEvent $event): void
    {
        if (findModule(\Modules::PRICE_LEVELS)) {
            Contexts::get(PriceLevelContext::class)->clearCache();
        }

        Contexts::get(UserContext::class)->clearCache();
    }
}
