<?php

namespace App\Notifications;

use App\Models\Offboarding;

class OffboardingClearanceCompleteNotification extends HrmsNotification
{
    public function __construct(
        public Offboarding $offboarding
    ) {}

    public function notificationCategory(): string
    {
        return 'offboarding';
    }

    public function notificationSubject(): string
    {
        $name = $this->offboarding->user?->name ?? 'Employee';

        return 'Exit clearance complete — ' . $name;
    }

    public function notificationLines(): array
    {
        return [
            'All exit clearance tasks are complete for ' . ($this->offboarding->user?->name ?? 'the employee') . '.',
            'F&F settlement is ready for approval.',
            'LWD: ' . ($this->offboarding->last_working_date?->format('d M Y') ?? '—'),
        ];
    }

    public function actionUrl(): ?string
    {
        if ($this->offboarding->fnfSettlement) {
            return route('fnf.show', $this->offboarding->fnfSettlement);
        }

        return route('offboardings.show', $this->offboarding);
    }

    public function actionLabel(): string
    {
        return 'Open F&F worksheet';
    }

    public function toArray(object $notifiable): array
    {
        return [
            'type' => 'offboarding_clearance_complete',
            'message' => 'Exit clearance complete for ' . ($this->offboarding->user?->name ?? 'employee') . '. F&F is pending approval.',
            'offboarding_id' => $this->offboarding->id,
            'url' => $this->actionUrl(),
        ];
    }
}
