<?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 ReservationConfirmation extends Mailable
{
    use Queueable, SerializesModels;

    public function __construct(
        public Reservation $reservation
    ) {}

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

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

    public function content(): Content
    {
        return new Content(
            view: 'emails.reservation-confirmation',
            with: [
                'confirmationUrl' => route('reservation.confirmation', ['token' => $this->reservation->token]),
            ],
        );
    }
}
