<?php

/*
 * This file is part of the VITICORE2 package.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CpCreation\VitiCore\Bridge\Symfony\Bundle\EventListener;

use CpCreation\VitiCore\Bridge\Symfony\Bundle\Event\UserAccountVerifiedEvent;
use CpCreation\VitiCore\Cart\Repository\CartRepository;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;

#[AsEventListener(event: UserAccountVerifiedEvent::class)]
final readonly class AttachGuestOrdersOnAccountVerificationListener
{
    public function __construct(
        private CartRepository $cartRepository,
    ) {
    }

    public function __invoke(UserAccountVerifiedEvent $event): void
    {
        $this->cartRepository->attachGuestCompletedOrdersToUserByEmail($event->user());
    }
}
