<?php

namespace App\Notifications;

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

class PolicyNotification extends Notification
{
    use Queueable;

    protected $notificationData;

    public function __construct($notificationData)
    {
        $this->notificationData = $notificationData;
    }

    public function via($notifiable)
    {
        return ['mail'];
    }

    public function toMail($notifiable)
    {
        $mailMessage = (new MailMessage)
            ->subject('Your Policy Cover Note - Policy Number: ' . $this->notificationData['national_id'])
            ->greeting('Dear Mr/Ms ' . $this->notificationData['member_name'])
            ->line('Please find attached the cover note for your ' . $this->notificationData['policy_name'] . ' policy, containing essential details, including your policy number and coverage terms.')
            ->line('Kindly review it carefully.')
            ->line('For additional information or to correct any details, please contact our Mbabane Burial Benefits Society team:')
            ->line('Phone: (+268) 2404 2888')
            ->line('Email: info@mbbs.co.sz')
            ->line('Our office hours are Monday to Friday from 12:00 am to 12:00 am.')
            ->line('When reaching out or sending documents, please quote your policy number or have it ready when you call.')
            ->line('Best Regards,')
            ->line('Mbabane Burial Benefits Society')
            ->line('Tel: (+268) 2404 2888')
            ->line('Website: https://mbbs.co.sz/');

        // Attach PDF
if (!empty($this->notificationData['pdf']) && file_exists($this->notificationData['pdf'])) {
    $mailMessage->attach($this->notificationData['pdf'], [
        'as' => 'Policy_Details_' . $this->notificationData['national_id'] . '.pdf', // Dynamic file name
        'mime' => 'application/pdf',
    ]);
}


        // Disclaimer
        $mailMessage->line('---')
            ->line('Disclaimer:')
            ->line('The content of this email is confidential and intended for the recipient specified in this message only. It is strictly forbidden to share any part of this message with any third party, without written consent of the sender.');

        return $mailMessage;
    }
}
