<?php

namespace App\Domains\MailTest\Mailables;

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

class TestMail extends Mailable
{
    use Queueable, SerializesModels;

    public function __construct(
        public readonly string $mailSubject,
        public readonly string $mailMessage,
        public readonly Tenant $tenant,
    ) {}

    public function envelope(): Envelope
    {
        return new Envelope(subject: $this->mailSubject);
    }

    public function content(): Content
    {
        $this->tenant->loadMissing(['headerLogo', 'footerLogo']);

        return new Content(
            view: 'mail.test',
            with: [
                'tenant' => $this->tenant,
                'headerLogoUrl' => $this->tenant->headerLogo?->getTemporaryUrl(1440),
                'footerLogoUrl' => $this->tenant->footerLogo?->getTemporaryUrl(1440),
            ],
        );
    }
}
