<?php

namespace App\Notifications;

use App\Models\Termination;
use Illuminate\Support\Str;

class TerminationRecordedNotification extends HrmsNotification
{
    public function __construct(
        public Termination $termination
    ) {}

    public function notificationCategory(): string
    {
        return 'resignation';
    }

    public function notificationSubject(): string
    {
        $name = $this->termination->user?->name ?? 'An employee';

        return 'Termination recorded — ' . $name;
    }

    public function notificationLines(): array
    {
        $user = $this->termination->user;

        return [
            ($user?->name ?? 'An employee') . ' has a termination on record.',
            'Date: ' . $this->termination->termination_date?->format('d M Y'),
            'Type: ' . ($this->termination->reason_type ?? '—'),
            'Reason: ' . Str::limit((string) ($this->termination->reason ?? '—'), 120),
        ];
    }

    public function actionUrl(): ?string
    {
        return route('terminations.index');
    }

    public function actionLabel(): string
    {
        return 'Review terminations';
    }

    public function toArray(object $notifiable): array
    {
        $user = $this->termination->user;

        return [
            'type' => 'termination_recorded',
            'message' => ($user?->name ?? 'An employee') . ' termination recorded.',
            'termination_id' => $this->termination->id,
            'url' => route('terminations.index'),
        ];
    }
}
