<?php

namespace App\Mail;

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

/**
 * Sent to the sales desk and (when we hold an address) the customer, the moment
 * an order is taken — before any invoice exists. It is a confirmation of what
 * was ordered and when it is due, not a demand for payment.
 */
class SalesOrderCreated extends Mailable
{
    use Queueable, SerializesModels;

    public function __construct(public readonly SalesOrder $order) {}

    public function envelope(): Envelope
    {
        return new Envelope(
            subject: 'New Sales Order — '.$this->order->order_number,
        );
    }

    public function content(): Content
    {
        return new Content(
            markdown: 'emails.sales-order-created',
            with: [
                'order' => $this->order,
                'customer' => $this->order->customer,
                'items' => $this->order->items,
            ],
        );
    }
}
