<?php

namespace App\Mail;

use App\Models\EmailBroadcast;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class BroadcastEmail extends Mailable
{
    use Queueable;
    use SerializesModels;

    public function __construct(
        public EmailBroadcast $broadcast,
        public ?User $recipient = null,
    ) {
    }

    public function build(): self
    {
        return $this
            ->subject($this->broadcast->subject)
            ->view('emails.broadcast')
            ->with([
                'broadcast' => $this->broadcast,
                'recipient' => $this->recipient,
            ]);
    }
}
