<?php

namespace App\Notifications;

use App\Models\Expense;
use Illuminate\Support\Str;

class ExpenseSubmittedNotification extends HrmsNotification
{
    public function __construct(
        public Expense $expense
    ) {}

    public function notificationCategory(): string
    {
        return 'expense';
    }

    public function notificationSubject(): string
    {
        $name = $this->expense->claimant?->name ?? 'An employee';

        return 'Expense claim pending approval — ' . $name;
    }

    public function notificationLines(): array
    {
        $claimant = $this->expense->claimant;

        return [
            ($claimant?->name ?? 'An employee') . ' submitted an expense claim.',
            'Category: ' . $this->expense->category,
            'Amount: ₹' . number_format((float) $this->expense->amount, 2),
            'Date: ' . $this->expense->date?->format('d M Y'),
            'Description: ' . Str::limit((string) ($this->expense->description ?? '—'), 120),
        ];
    }

    public function actionUrl(): ?string
    {
        return route('expenses.index', ['status' => 'pending']);
    }

    public function actionLabel(): string
    {
        return 'Review expenses';
    }

    public function toArray(object $notifiable): array
    {
        $claimant = $this->expense->claimant;

        return [
            'type' => 'expense_submitted',
            'message' => ($claimant?->name ?? 'An employee') . ' submitted an expense of ₹' . number_format((float) $this->expense->amount, 2) . '.',
            'expense_id' => $this->expense->id,
            'employee_name' => $claimant?->name,
            'amount' => $this->expense->amount,
            'category' => $this->expense->category,
            'url' => route('expenses.index', ['status' => 'pending']),
        ];
    }
}
