<?php

namespace App\Mail\Applications;

use App\Models\Applications\Application;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class NotifyApplicationExpertChanged extends Mailable implements ShouldQueue {
    use Queueable, SerializesModels;

    public Application $application;
    public User $recipient;

    public function __construct(Application $application, User $recipient) {
        $this->application = $application;
        $this->recipient = $recipient;
    }

    public function build(): NotifyApplicationExpertChanged {
        $expert = $this->application->expert()->first();
        $subject = "Назначен эксперт по заявке №{$this->application->number}";
        if ($this->recipient->id === ($expert->user->id ?? null)) $subject = "Вы назначены экспертом по заявке №{$this->application->number}";
        return $this->subject($subject)->view("mail.applications.expert-changed");
    }
}
