<?php

namespace App\Mail;

use App\Models\ContactMessage;
use App\Models\Setting;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;

class ContactMessageNotification extends Mailable
{
    use Queueable, SerializesModels;

    public function __construct(
        public ContactMessage $contactMessage,
        public string $recipientEmail
    ) {}

    public function envelope(): Envelope
    {
        $from = app(\App\Services\MailService::class)->getFromAddress();

        return new Envelope(
            to: [$this->recipientEmail],
            from: new \Illuminate\Mail\Mailables\Address($from['address'], $from['name']),
            subject: 'Nouveau message de contact : ' . ($this->contactMessage->subject ?: 'Sans sujet'),
            replyTo: [$this->contactMessage->email],
        );
    }

    public function content(): Content
    {
        $logo = Setting::get('logo');
        $logoUrl = $logo ? asset('storage/'.$logo) : route('branding.logo');
        $siteName = Setting::get('site_name', config('cms.name', config('app.name')));

        return new Content(
            view: 'emails.contact-message-notification',
            with: [
                'logoUrl' => $logoUrl,
                'siteName' => $siteName,
            ],
        );
    }
}
