<?php

namespace App\Notifications;

use App\Models\AttendanceRegularization;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;

class AttendanceRegularizationReviewed extends Notification
{
    use Queueable;

    public function __construct(
        public AttendanceRegularization $regularization,
        public string $outcome
    ) {}

    public function via(object $notifiable): array
    {
        return ['database'];
    }

    public function toArray(object $notifiable): array
    {
        $reviewer = $this->regularization->reviewer;
        return [
            'type' => 'attendance_regularization_reviewed',
            'message' => 'Your attendance regularization for ' . $this->regularization->date?->format('d M Y') . ' was ' . $this->outcome . '.',
            'outcome' => $this->outcome,
            'date' => $this->regularization->date?->format('Y-m-d'),
            'reviewer_name' => $reviewer?->name,
            'review_remarks' => \Illuminate\Support\Str::limit($this->regularization->review_remarks ?? '', 80),
            'regularization_id' => $this->regularization->id,
            'url' => route('attendance-regularizations.index'),
        ];
    }
}
