<?php

namespace App\Notifications;

use App\Models\EmployeeLeave;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Facades\Auth;
use Swift_Message;

class AsaMeeting extends Notification
{
    use Queueable;

    private string $message;

    /**
     * Create a new notification instance.
     */
    public function __construct(private \App\Models\AsaMeeting $asaMeeting)
    {
        $this->message = $this->generateMessage();
    }

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

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

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

        $fullname = $user->first_name . ' ' . $user->last_name;

        return [
            'asa_meeting_id' => $this->asaMeeting->id,
            'message' => $this->message,
            'title' => $fullname.' invited you for a meeting',
            'url' => 'meeting-calendar/calendar',
            'created_by' => $this->asaMeeting->employee_id
        ];
    }

    /**
     * Generate the message based on leave status.
     */
    private function generateMessage(): string
    {
        $user = Auth::user();

        $fullname = $user->first_name . ' ' . $user->last_name;

        return $fullname.' invited you for a meeting on '.$this->asaMeeting->start_datetime.' to '.$this->asaMeeting->end_datetime.'.';
    }
}
