<?php

namespace KupShop\SKEETBundle\EventListener;

use KupShop\AdminBundle\Util\ActivityLog;
use KupShop\POSBundle\Event\PosPaymentEvent;
use KupShop\SKEETBundle\Util\SKEETWorker;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Contracts\Service\Attribute\Required;

class PaymentListener implements EventSubscriberInterface
{
    #[Required]
    public SKEETWorker $skeetWorker;

    public static function getSubscribedEvents()
    {
        $events[PosPaymentEvent::POS_SELECT_PAYMENT] = [
            ['processPosInsertOrSelectPayment', 200],
        ];

        $events[PosPaymentEvent::POS_INSERT_PAYMENT] = [
            ['processPosInsertOrSelectPayment', 200],
        ];

        return $events;
    }

    public function processPosInsertOrSelectPayment(PosPaymentEvent $event)
    {
        try {
            $this->skeetWorker->openEETDrawer();
        } catch (\Exception $e) {
            addActivityLog(ActivityLog::SEVERITY_NOTICE,
                ActivityLog::TYPE_COMMUNICATION,
                "SK EET: Otevření zásuvky se nezdařilo: {$e->getMessage()}");
        }
    }
}
