<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class JobApplication extends Notification
{
    use Queueable;

    private string $message;
    public $applicant;
    /**
     * Create a new notification instance.
     */
    public function __construct($applicant)
    {
        $this->applicant = $applicant;
        $this->message = $this->generateMessage();
    }

    /**
     * Get the notification's delivery channels.
     *
     * @return array<int, string>
     */
    public function via(object $notifiable): array
    {
        return ['mail'];
    }

    /**
     * Get the mail representation of the notification.
     */
    public function toMail(object $notifiable): MailMessage
    {
        return (new MailMessage)
        ->view('emails.jobapplication', [
            'headerImageUrl' => asset('images/AUTOHUB25_BANNER.png'), // URL of the image
            'msg' => $this->message,
        ])
        ->subject('Job Application Notification');
    }

    /**
     * Get the array representation of the notification.
     *
     * @return array<string, mixed>
     */
    public function toArray(object $notifiable): array
    {
        return [
            //
        ];
    }

    private function generateMessage(): string
    {
        $fullname = $this->applicant->firstname . ' ' . $this->applicant->lastname;
        $job_title = $this->applicant->position;
        $cover_letter = $this->applicant->cover_letter;

        return "$fullname submitted an application for the position of \"$job_title\".
        
        Applicant Covert Letter:
        $cover_letter";
    }
}
