<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use App\Models\StaffApplication;

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

    public StaffApplication $application;

    /**
     * Create a new message instance.
     */
    public function __construct(StaffApplication $application)
    {
        $this->application = $application;
    }

    /**
     * Build the message.
     */
    public function build()
    {
        $topicLabel = match ($this->application->topic ?? 'apply') {
            'apply' => 'Application',
            'bug' => 'Bug Report',
            'contact' => 'Contact',
            default => 'Message',
        };

        return $this->subject("New {$topicLabel}: " . ($this->application->name ?? 'Unnamed'))
                ->from(config('mail.from.address'), config('mail.from.name'))
                ->view('emails.staff_application_received')
                ->text('emails.staff_application_received_plain')
                ->with(['application' => $this->application, 'topicLabel' => $topicLabel]);
    }
}
