<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class MarkdownMail extends Mailable
{
    use Queueable, SerializesModels;

    public $data;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct(string $view, string $subject, array $data = [])
    {
        $this->data = $data;
        $this->view = $view;
        $this->subject = $subject;
    }

    /**
     * Build the message.
     */
    public function build(): static
    {
        $mail = $this->subject($this->subject)
            ->markdown($this->view)
            ->with($this->data);

        if ($this->data['attachments']) {
            $mail->attach($this->data['attachments']);
        }

        return $mail;
    }
}
