<?php

namespace App\Mail;

use App\Mail\Concerns\RidesALane;
use App\Mail\Concerns\SendsFromMailbox;
use App\Models\Customer;
use App\Services\Mail\MailCatalogue;
use App\Services\Mail\MailPurpose;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;

/**
 * A message an operator wrote, in the console, to one customer.
 *
 * Everything else this application sends is a mail the SYSTEM decided to send:
 * an invoice, a maintenance window, credentials. This is the one a person
 * writes — the answer to "können Sie unsere Daten übernehmen?" — and it exists
 * so that answering does not mean opening a mail client, finding the address,
 * and leaving no trace in the console that it ever happened.
 *
 * Sent from the support mailbox, because that is where the customer's reply
 * should land.
 */
class OperatorMessageMail extends Mailable implements ShouldQueue
{
    use Queueable, RidesALane, SendsFromMailbox, SerializesModels;

    public function __construct(
        public Customer $customer,
        public string $subjectLine,
        public string $bodyText,
    ) {
        $this->mailer(MailCatalogue::mailer('operator-message'));
    }

    public function envelope(): Envelope
    {
        return $this->mailboxEnvelope(MailPurpose::SUPPORT, $this->subjectLine, 'operator-message');
    }

    public function content(): Content
    {
        return new Content(view: 'mail.operator-message', with: [
            'name' => $this->customer->name,
            'bodyText' => $this->bodyText,
        ]);
    }
}
