<?php

namespace App\Jobs;

use App\Models\Server;
use App\Services\ServerScraperService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable as QueueableTrait;
use Illuminate\Queue\SerializesModels;

class ScrapeServer implements ShouldQueue
{
    use QueueableTrait, Queueable, SerializesModels;

    public int $timeout = 30;
    public int $tries = 2;

    public function __construct(public Server $server) {}

    public function uniqueId(): string
    {
        return 'scrape:' . $this->server->id;
    }

    public function handle(ServerScraperService $scraper): void
    {
        if (!$this->server->is_active) return;
        $scraper->scrape($this->server);
    }
}
