<?php

declare(strict_types=1);

namespace Apexl\Io\Jobs\Helpers;

use Apexl\Io\Jobs\Entities\QueueJob;
use Apexl\Io\Jobs\Interfaces\QueueTaskInterface;
use Throwable;

readonly final class QueueJobTask implements QueueTaskInterface
{
    public function __construct(private QueueJob $queueJob) {}

    public function lock(): void
    {
        $this->queueJob->lock();
    }

    public function unlock(): void
    {
        $this->queueJob->unlock();
    }

    public function markProcessed(): void
    {
        $this->queueJob->markProcessed();
    }

    public function run(): void
    {
        $this->queueJob->run();
    }

    public function name(): string
    {
        return sprintf('Queue Job %d (%s)', $this->queueJob->id, $this->queueJob->handler);
    }

    public function handleFailure(string $task, Throwable $throwable): void
    {
        $this->queueJob->handleFailure($task, $throwable);
    }

    public function isLocked(): bool
    {
        return $this->queueJob->locked;
    }

    public function shouldRun(): bool
    {
        return $this->queueJob->shouldRun();
    }

    public function defer(): void
    {
        $this->queueJob->defer($this->queueJob->skipDelaySeconds());
    }

    public function delete(): void
    {
        $this->queueJob->delete();
    }
}
