<?php

namespace App\Mail;

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

class PayrollMail extends Mailable
{
    use Queueable, SerializesModels;

    public $row;
    public $subject;
    public $message;
    public $siteName;
    public $appUrl;

    /**
     * Create a new message instance.
     *
     * @param mixed $row The model record (e.g. \App\Models\Payroll)
     * @param string $subject Email subject
     * @param string $message Optional text message
     * @param string $siteName Site name from settings
     * @param string $appUrl Application URL
     */
    public function __construct($row, $subject, $message, $siteName, $appUrl)
    {
        $this->row = $row;
        $this->subject = $subject;
        $this->message = $message ?: 'Please find your record details below.';
        $this->siteName = $siteName;
        $this->appUrl = $appUrl;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->subject($this->subject)
            ->view('emails.payrolls')
            ->with([
                'row' => $this->row,
                'message' => $this->message,
                'siteName' => $this->siteName,
                'appUrl' => $this->appUrl,
            ]);
    }
}
