<?php

namespace KupShop\RestrictionsBundle\EventListener;

use KupShop\CatalogBundle\Event\FilterParamsEvent;
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
use KupShop\RestrictionsBundle\Utils\Restrictions;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class FilterParamsListener implements EventSubscriberInterface
{
    public static function getSubscribedEvents()
    {
        $events = [];

        if (!findModule(\Modules::PRODUCTS_SECTIONS, \Modules::SUB_ELASTICSEARCH)) {
            $events[FilterParamsEvent::DEFAULT] = [
                ['addFilterParam', 200],
            ];
        }

        return $events;
    }

    /**
     * @var FilterParamsEvent
     */
    public function addFilterParam(FilterParamsEvent $event)
    {
        $restrictionsSpec = ServiceContainer::getService(Restrictions::class);

        $event->addFilterSpec($restrictionsSpec->getRestrictionSpec(), 'restrictions');
    }
}
