<?php

namespace App\Jobs;

use App\Models\NotificationLog;
use App\Services\NotificationService;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;

class SendAppointmentReminder implements ShouldQueue
{
    use Queueable;

    public int $tries = 4;

    public array $backoff = [60, 300, 900];

    public function __construct(public readonly int $notificationLogId) {}

    public function handle(NotificationService $notifications): void
    {
        $log = NotificationLog::query()->find($this->notificationLogId);

        if (! $log || in_array($log->status, ['sent', 'superseded', 'skipped'], true)) {
            return;
        }

        $notifications->send($log);
    }
}
