<?php

namespace App\Notifications;

use App\Models\Appreciation;
use Illuminate\Support\Str;

class AppreciationReceivedNotification extends HrmsNotification
{
    public function __construct(
        public Appreciation $appreciation
    ) {}

    public function notificationCategory(): string
    {
        return 'hr_recognition';
    }

    public function notificationSubject(): string
    {
        return 'You received recognition — ' . ($this->appreciation->title ?? 'Appreciation');
    }

    public function notificationLines(): array
    {
        $from = $this->appreciation->givenByUser?->name ?? 'Your team';

        return [
            $from . ' recognized your contribution.',
            'Title: ' . ($this->appreciation->title ?? '—'),
            Str::limit((string) ($this->appreciation->description ?? ''), 160),
        ];
    }

    public function actionUrl(): ?string
    {
        return route('my-hr-records.index') . '#appreciations';
    }

    public function actionLabel(): string
    {
        return 'View my records';
    }

    public function toArray(object $notifiable): array
    {
        return [
            'type' => 'appreciation_received',
            'message' => 'You received appreciation: ' . ($this->appreciation->title ?? ''),
            'appreciation_id' => $this->appreciation->id,
            'url' => route('my-hr-records.index') . '#appreciations',
        ];
    }
}
