<?php

namespace App\Mail;

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

class ChequeMaturityReminderMail extends Mailable
{
    use Queueable, SerializesModels;

    public function __construct(public readonly Transaction $transaction) {}

    public function envelope(): Envelope
    {
        return new Envelope(subject: 'Payment Reminder — Cheque Due Tomorrow');
    }

    public function content(): Content
    {
        return new Content(
            view: 'mail.cheque-maturity',
            with: [
                'txn' => $this->transaction,
                'customer' => $this->transaction->customer,
                'invoiceRefs' => $this->transaction->claims->load('invoice')->pluck('invoice.invoice_number')->filter()->implode(', '),
            ],
        );
    }
}
