<?php

namespace App\Mail;

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

class NewReservationNotification extends Mailable
{
    use Queueable, SerializesModels;

    public function __construct(
        public Reservation $reservation,
        public string $recipientEmail
    ) {}

    public function envelope(): Envelope
    {
        $from = app(\App\Services\MailService::class)->getFromAddress();
        $serviceName = $this->reservation->slot?->service?->name ?? 'Réservation';

        return new Envelope(
            to: [$this->recipientEmail],
            from: new \Illuminate\Mail\Mailables\Address($from['address'], $from['name']),
            subject: 'Nouvelle réservation — '.$serviceName,
            replyTo: [$this->reservation->customer_email],
        );
    }

    public function content(): Content
    {
        return new Content(
            view: 'emails.new-reservation-notification',
            with: [
                'adminReservationUrl' => route('admin.reservation.reservations.show', $this->reservation),
            ],
        );
    }
}
