<?php

declare(strict_types=1);

namespace KupShop\AgeVerifyBundle\EventSubscribers;

use KupShop\OrderingBundle\Event\OrderDeliveryEvent;
use Query\Operator;

class OrderEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
{
    public static function getSubscribedEvents()
    {
        return [
            OrderDeliveryEvent::class => [
                ['updateLegalAge', 200],
            ],
        ];
    }

    public function updateLegalAge(OrderDeliveryEvent $event)
    {
        $orderId = $event->getOrder()->id;
        sqlQueryBuilder()->update('users_age_verification')
            ->directValues(['legal_age' => 'Y'])
            ->where(Operator::equals(['id_order' => $orderId]))
            ->execute();
    }
}
