<?php

namespace App\Service;

use App\DataObjects\ContactData;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\Mailer\MailerInterface;

final readonly class ContactService
{
    public function __construct(
        private MailerInterface $mailer,
        #[Autowire(env: 'CONTACT_MAIL')]
        private string $contactEmail,
        #[Autowire(env: 'SENDER_MAIL')]
        private string $senderEmail,
    ){
    }

    public function send(ContactData $data): void
    {
        $mail = (new TemplatedEmail())
            ->htmlTemplate('email/contact.html.twig')
            ->context(['data' => $data])
            ->subject('Kontakt aufnahme')
            ->replyTo($data->email)
            ->from($this->senderEmail)
            ->to($this->contactEmail);

        $this->mailer->send($mail);
    }
}