<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Storage;
use Mtc\MercuryDataModels\Invoice;

class OverdueInvoiceNotification extends Mailable implements ShouldQueue
{
    use Queueable;
    use SerializesModels;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct(protected readonly Invoice $invoice)
    {
        //
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->view('invoices.overdue')
            ->when(
                $this->invoice->pdf_path,
                fn ($mail) => $mail->attach(Storage::disk('file-storage')->get($this->invoice->pdf_path))
            );
    }
}
