<?php

namespace App\Notifications;

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

class SendGeneratedReport extends Notification
{
    use Queueable;

    public $reportData;

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

    /**
     * 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
    {
        $attachmentPath = storage_path('app/save_reports/' . $this->reportData['attachment']);
        
        return (new MailMessage)
                    ->subject($this->reportData['subject'])
                    ->greeting('Good Day!')
                    ->line($this->reportData['sender'] . ' sent you a generated report for you to check.')
                    // ->line('Report ID: ' . $this->reportData['report_id'])
                    // ->line('Employee ID: ' . $this->reportData['employee_id'])
                    ->line(strip_tags($this->reportData['message'])) // Strip HTML tags for plain text
                    ->attach($attachmentPath, [
                        'as' => 'report-' . date('Y-m-d') . '.csv',
                        'mime' => 'text/csv',
                    ])
                    ->line('Thank you for using our application!');
    }

    /**
     * Get the array representation of the notification.
     *
     * @return array<string, mixed>
     */
    public function toArray(object $notifiable): array
    {
        return [
            'report_id' => $this->reportData['report_id'],
            'employee_id' => $this->reportData['employee_id'],
            'subject' => $this->reportData['subject'],
            'attachment' => $this->reportData['attachment'],
        ];
    }
}