<?php

namespace App\Jobs;

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

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

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

    public function __construct(public Website $website) {}

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

    public function handle(WebsiteCheckerService $checker): void
    {
        if (!$this->website->is_active) return;
        $checker->check($this->website);
    }
}
