<?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 NewsletterMail extends Mailable
{
    use Queueable, SerializesModels;

    public function __construct(
        public string $subject,
        public string $content,
        public string $toEmail,
        public ?string $subscriberName = null
    ) {}

    public function envelope(): Envelope
    {
        $from = app(\App\Services\MailService::class)->getFromAddress();

        return new Envelope(
            to: [$this->toEmail],
            from: new Address($from['address'], $from['name']),
            subject: $this->subject,
        );
    }

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