<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Event\Worker\Monitoring;

final class WorkerStalePolicy
{
    public function __construct(
        private readonly int $heartbeatTimeoutSeconds = 60,
        private readonly int $runningTimeoutSeconds = 300,
        private readonly int $idleTimeoutSeconds = 900
    ) {}

    public static function default(): self
    {
        return new self();
    }

    public static function strict(): self
    {
        return new self(5, 10, 30);
    }

    public function heartbeatTimeoutSeconds(): int
    {
        return max(1, $this->heartbeatTimeoutSeconds);
    }

    public function runningTimeoutSeconds(): int
    {
        return max(1, $this->runningTimeoutSeconds);
    }

    public function idleTimeoutSeconds(): int
    {
        return max(1, $this->idleTimeoutSeconds);
    }

    public function toArray(): array
    {
        return [
            'heartbeatTimeoutSeconds' => $this->heartbeatTimeoutSeconds(),
            'runningTimeoutSeconds' => $this->runningTimeoutSeconds(),
            'idleTimeoutSeconds' => $this->idleTimeoutSeconds(),
        ];
    }
}
