<?php

namespace App\Event\Signature;

use App\Entity\Account;
use App\Entity\AccountLoginRegister;
use App\Service\Mailer\Mailer;
use App\Service\Signature\Client;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use Symfony\Component\Security\Http\Event\LoginSuccessEvent;

#[AsEventListener(event: DevisSend::class, method: 'onDevisSend')]
class DevisSubscriber
{
    public function __construct(
        private readonly EntityManagerInterface $entityManager,
        private readonly Mailer  $mailer,
        private readonly Client $client,
    )
    {
    }

    public function onDevisSend(DevisSend $devisSend): void
    {
        $customer = $devisSend->getDevis()->getCustomer();
        $devis = $devisSend->getDevis();
        $signLink = $this->client->getLinkSign($devis->getSignatureId());


        $this->mailer->send($customer->getEmail(), $customer->getName()." ".$customer->getSurname(),"[Signature Ludikevent] - Signature de votre devis pour votre location","mails/sign/devis.twig",[
            'devis' => $devis,
            'signLink' => $signLink,
        ]);
    }
}
