<?php

namespace App\Jobs;

use App\Models\Ticket;
use App\Services\TicketNotificationService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class SendTicketSmsNotificationJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public int $tries = 3;
    public int $timeout = 60;

    public function __construct(
        private readonly int $ticketId,
        private readonly string $event,
        private readonly array $context = []
    ) {
    }

    public function backoff(): array
    {
        return [10, 30, 90];
    }

    public function handle(TicketNotificationService $ticketNotificationService): void
    {
        $ticket = Ticket::with(['customer', 'order'])->find($this->ticketId);
        if (!$ticket) {
            return;
        }

        $ticketNotificationService->sendSmsForCustomerEvent($ticket, $this->event, $this->context);
    }
}
