<?php

namespace App\Mail;

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

class NewOrderNotification extends Mailable
{
    use Queueable, SerializesModels;

    public function __construct(
        public Order $order,
        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: 'Nouvelle commande #' . $this->order->number,
            replyTo: [$this->order->customer_email],
        );
    }

    public function content(): Content
    {
        return new Content(
            view: 'emails.new-order-notification',
        );
    }
}
