<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Address;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;

class TemplateTestMail extends Mailable
{
    use Queueable, SerializesModels;

    public function __construct(
        public readonly string $templateTitle,
        public readonly string $emailSubject,
        public readonly string $renderedHtml,
        public readonly ?string $fromEmail = null,
        public readonly ?string $fromName = null,
        public readonly ?string $replyEmail = null,
        public readonly ?string $replyName = null,
    ) {}

    public function envelope(): Envelope
    {
        $subject = '[TEST] ' . ($this->emailSubject ?: 'Test Email');

        return new Envelope(
            subject: $subject,
            from: $this->fromEmail ? new Address($this->fromEmail, $this->fromName ?? '') : null,
            replyTo: $this->replyEmail ? [new Address($this->replyEmail, $this->replyName ?? '')] : [],
        );
    }

    public function content(): Content
    {
        return new Content(
            view: 'emails.template-test',
        );
    }

    public function attachments(): array
    {
        return [];
    }
}
