<?php

declare(strict_types=1);

namespace PhpWA\Storage;

use InvalidArgumentException;

final class RetryDecision
{
    /** @var int */ private $attempt;
    /** @var bool */ private $shouldSend;
    /** @var bool */ private $exhausted;
    /** @var int */ private $nextAllowedAt;

    public function __construct(int $attempt, bool $shouldSend, bool $exhausted, int $nextAllowedAt)
    {
        if ($attempt < 0 || $nextAllowedAt < 0 || ($shouldSend && $exhausted)) {
            throw new InvalidArgumentException('Retry decision is invalid.');
        }
        $this->attempt = $attempt;
        $this->shouldSend = $shouldSend;
        $this->exhausted = $exhausted;
        $this->nextAllowedAt = $nextAllowedAt;
    }

    public function attempt(): int { return $this->attempt; }
    public function shouldSend(): bool { return $this->shouldSend; }
    public function isExhausted(): bool { return $this->exhausted; }
    public function nextAllowedAt(): int { return $this->nextAllowedAt; }
}
