<?php

namespace App\Jobs;

use App\Models\InstallRequest;
use App\Services\OneCService;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class SendRequestTo1CJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public int $tries = 5;
    public int $backoff = 10;

    /**
     * Create a new job instance.
     */
    public function __construct(
        public int $requestId
    ) {}

    /**
     * Execute the job.
     */
    public function handle(OneCService $service): void
    {
        $request = InstallRequest::find($this->requestId);

        if (!$request) return;

        $service->sendCompletedRequest($request);
    }
}
