<?php

namespace App\Notifications;

use App\Models\Offboarding;
use App\Models\OffboardingChecklistItem;

class OffboardingChecklistAssignedNotification extends HrmsNotification
{
    public function __construct(
        public Offboarding $offboarding,
        public OffboardingChecklistItem $item
    ) {}

    public function notificationCategory(): string
    {
        return 'offboarding';
    }

    public function notificationSubject(): string
    {
        $name = $this->offboarding->user?->name ?? 'Employee';

        return 'Exit clearance task assigned — ' . $name;
    }

    public function notificationLines(): array
    {
        $employee = $this->offboarding->user;

        return [
            'You have been assigned an offboarding clearance task.',
            'Employee: ' . ($employee?->name ?? '—'),
            'Task: ' . $this->item->task_name,
            'Category: ' . ucfirst($this->item->category),
            'LWD: ' . ($this->offboarding->last_working_date?->format('d M Y') ?? '—'),
        ];
    }

    public function actionUrl(): ?string
    {
        return route('offboardings.show', $this->offboarding);
    }

    public function actionLabel(): string
    {
        return 'Open clearance checklist';
    }

    public function toArray(object $notifiable): array
    {
        return [
            'type' => 'offboarding_checklist_assigned',
            'message' => 'Clearance task assigned: ' . $this->item->task_name . ' for ' . ($this->offboarding->user?->name ?? 'employee') . '.',
            'offboarding_id' => $this->offboarding->id,
            'checklist_item_id' => $this->item->id,
            'task_name' => $this->item->task_name,
            'url' => route('offboardings.show', $this->offboarding),
        ];
    }
}
