<?php

namespace App\Mail;

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

/**
 * Email sent to the client when a loan is approved.
 */
class LoanApproved extends Mailable
{
    use Queueable, SerializesModels;

    public Loan $loan;

    // Create a new message for the approved loan.
    public function __construct(Loan $loan)
    {
        $this->loan = $loan;
    }

    // Build the email subject.
    public function envelope(): Envelope
    {
        return new Envelope(
            subject: 'Your Loan Application Has Been Approved - ' . $this->loan->loan_number,
        );
    }

    // Build the view and data passed to the template.
    public function content(): Content
    {
        return new Content(
            view: 'emails.loan-approved',
            with: [
                'loan' => $this->loan,
                'client' => $this->loan->client,
            ],
        );
    }

    // No attachments for this email.
    public function attachments(): array
    {
        return [];
    }
}
