<?php

namespace KupShop\OSSVatsBundle\EventSubscriber;

use KupShop\KupShopBundle\Event\CronEvent;
use KupShop\OSSVatsBundle\Util\VatsUtil;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class OSSVatsSubscriber implements EventSubscriberInterface
{
    /** @var VatsUtil */
    protected $vatsUtil;

    public function __construct(VatsUtil $vatsUtil)
    {
        $this->vatsUtil = $vatsUtil;
    }

    public static function getSubscribedEvents()
    {
        return [
            CronEvent::RUN_EXPENSIVE => [
                ['loadVatRates', 1500],
            ],
        ];
    }

    public function loadVatRates()
    {
        $this->vatsUtil->updateVatRates();
        $this->vatsUtil->refreshVatsCnsRelations();
    }
}
