<?php

namespace App\Notifications;

use App\Models\Warning;
use Illuminate\Support\Str;

class WarningIssuedNotification extends HrmsNotification
{
    public function __construct(
        public Warning $warning
    ) {}

    public function notificationCategory(): string
    {
        return 'complaints';
    }

    public function notificationSubject(): string
    {
        return 'Warning issued — ' . ($this->warning->subject ?? 'Disciplinary warning');
    }

    public function notificationLines(): array
    {
        return [
            'A warning has been recorded on your employee file.',
            'Subject: ' . ($this->warning->subject ?? '—'),
            'Severity: ' . ucfirst((string) ($this->warning->severity ?? 'medium')),
            'Date: ' . $this->warning->warning_date?->format('d M Y'),
            Str::limit((string) ($this->warning->description ?? ''), 160),
        ];
    }

    public function actionUrl(): ?string
    {
        return route('my-hr-records.index') . '#warnings';
    }

    public function actionLabel(): string
    {
        return 'View my records';
    }

    public function toArray(object $notifiable): array
    {
        return [
            'type' => 'warning_issued',
            'message' => 'Warning issued: ' . ($this->warning->subject ?? ''),
            'warning_id' => $this->warning->id,
            'url' => route('my-hr-records.index') . '#warnings',
        ];
    }
}
