<?php

namespace App\Notifications;

use App\Models\FnfSettlement;

class FnfPendingApprovalNotification extends HrmsNotification
{
    public function __construct(
        public FnfSettlement $settlement
    ) {}

    public function notificationCategory(): string
    {
        return 'fnf';
    }

    public function notificationSubject(): string
    {
        $name = $this->settlement->user?->name ?? 'Employee';

        return 'F&F settlement pending approval — ' . $name;
    }

    public function notificationLines(): array
    {
        $user = $this->settlement->user;

        return [
            'Offboarding clearance is complete for ' . ($user?->name ?? 'an employee') . '.',
            'F&F net payable: ₹' . number_format((float) $this->settlement->net_payable, 2),
            'Please review and approve the settlement worksheet.',
        ];
    }

    public function actionUrl(): ?string
    {
        return route('fnf.show', $this->settlement);
    }

    public function actionLabel(): string
    {
        return 'Open F&F worksheet';
    }

    public function toArray(object $notifiable): array
    {
        $user = $this->settlement->user;

        return [
            'type' => 'fnf_pending_approval',
            'message' => 'F&F settlement for ' . ($user?->name ?? 'employee') . ' is pending approval.',
            'fnf_id' => $this->settlement->id,
            'employee_name' => $user?->name,
            'net_payable' => $this->settlement->net_payable,
            'url' => route('fnf.show', $this->settlement),
        ];
    }
}
