<?php

namespace App\Notifications;

use App\Models\Expense;
use Illuminate\Support\Str;

class ExpenseReviewedNotification extends HrmsNotification
{
    public function __construct(
        public Expense $expense,
        public string $outcome
    ) {}

    public function notificationCategory(): string
    {
        return 'expense';
    }

    public function notificationSubject(): string
    {
        return 'Your expense claim was ' . $this->outcome;
    }

    public function notificationLines(): array
    {
        $lines = [
            'Your expense claim (' . $this->expense->category . ') was ' . $this->outcome . '.',
            'Amount: ₹' . number_format((float) $this->expense->amount, 2),
        ];

        if ($this->expense->review_remarks) {
            $lines[] = 'Remarks: ' . Str::limit((string) $this->expense->review_remarks, 120);
        }

        return $lines;
    }

    public function actionUrl(): ?string
    {
        return route('expenses.index');
    }

    public function actionLabel(): string
    {
        return 'View expenses';
    }

    public function toArray(object $notifiable): array
    {
        return [
            'type' => 'expense_reviewed',
            'message' => 'Your expense claim for ₹' . number_format((float) $this->expense->amount, 2) . ' was ' . $this->outcome . '.',
            'outcome' => $this->outcome,
            'expense_id' => $this->expense->id,
            'remark' => Str::limit((string) ($this->expense->review_remarks ?? ''), 80),
            'url' => route('expenses.index'),
        ];
    }
}
