<?php

namespace App\Mail;

use App\Models\Campaign;
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 CampaignTestMail extends Mailable
{
    use Queueable, SerializesModels;

    public function __construct(
        public readonly Campaign $campaign,
        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->campaign->email_subject ?: '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.campaign-test');
    }

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