<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Cache;

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

    public int $tries = 1;

    public int $timeout = 15;

    public function __construct(public string $token)
    {
    }

    public function handle(): void
    {
        Cache::put(self::cacheKey($this->token), now()->utc()->toIso8601String(), now()->addMinutes(5));
    }

    public static function cacheKey(string $token): string
    {
        return 'release:queue-probe:'.$token;
    }
}
