<?php
declare(strict_types=1);

namespace PpPhp\Core\Platform\Event\Retry\Policy;

use PpPhp\Core\Platform\Event\Retry\Contracts\RetryPolicyInterface;
use PpPhp\Core\Platform\Event\Retry\RetryContext;

final class LinearRetryPolicy implements RetryPolicyInterface
{
    public function __construct(private readonly int $stepSeconds = 5) {}
    public function name(): string { return 'linear'; }
    public function shouldRetry(RetryContext $context): bool { return $context->attempt() < $context->maxAttempts(); }
    public function nextDelaySeconds(RetryContext $context): int { return max(0, $this->stepSeconds * max(1, $context->attempt())); }
}
