<?php

namespace App\Notifications;

use App\Models\Leave;

class LeaveRequestSubmittedNotification extends HrmsNotification
{
    public function __construct(
        public Leave $leave
    ) {}

    public function notificationCategory(): string
    {
        return 'leave';
    }

    public function notificationSubject(): string
    {
        return 'Leave request submitted';
    }

    public function notificationLines(): array
    {
        return [
            'Your leave request (' . ($this->leave->leaveType?->name ?? 'Leave') . ') was submitted and is pending approval.',
            'Dates: ' . $this->leave->start_date?->format('d M Y') . ' to ' . $this->leave->end_date?->format('d M Y'),
        ];
    }

    public function actionUrl(): ?string
    {
        return route('leaves.dashboard');
    }

    public function actionLabel(): string
    {
        return 'View leave';
    }

    public function toArray(object $notifiable): array
    {
        return [
            'type' => 'leave_request_submitted',
            'message' => 'Your leave request was submitted and is pending approval.',
            'leave_id' => $this->leave->id,
            'start_date' => $this->leave->start_date?->format('Y-m-d'),
            'end_date' => $this->leave->end_date?->format('Y-m-d'),
            'url' => route('leaves.dashboard'),
        ];
    }

    protected function fcmType(): string
    {
        return 'leave_request_submitted';
    }

    protected function fcmRoute(): string
    {
        return '/leave';
    }

    protected function fcmData(): array
    {
        return [
            'leave_id' => (string) $this->leave->id,
            'outcome' => 'pending',
        ];
    }
}
