<?php

namespace App\Mail;

use App\Models\Invoice;
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;

class OverdueNotice extends Mailable implements ShouldQueue
{
    use Queueable, SerializesModels;

    public function __construct(public Invoice $invoice) {}

    public function envelope(): Envelope
    {
        $daysOverdue = now()->diffInDays($this->invoice->due_date);

        return new Envelope(
            subject: "Overdue: Invoice {$this->invoice->invoice_number} is {$daysOverdue} day(s) overdue"
        );
    }

    public function content(): Content
    {
        return new Content(view: 'emails.overdue_notice');
    }
}
