<?php

declare(strict_types=1);

namespace KupShop\ReservationBundle\EventSubscriber;

use KupShop\KupShopBundle\Event\CronEvent;
use KupShop\ReservationBundle\Util\ReservationUtil;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class CronSubscriber implements EventSubscriberInterface
{
    private ReservationUtil $reservationUtil;

    public function __construct(ReservationUtil $reservationUtil)
    {
        $this->reservationUtil = $reservationUtil;
    }

    public static function getSubscribedEvents(): array
    {
        return [
            CronEvent::RUN_FREQUENT => [
                ['mergeReservations', 200],
            ],
        ];
    }

    public function mergeReservations(): void
    {
        $this->reservationUtil->mergeReservationsIntoOrders();
    }
}
