<?php

declare(strict_types=1);

namespace PhpWA\Client;

use InvalidArgumentException;

final class IncomingMessageResult
{
    public const COMMITTED = 'committed';
    public const DUPLICATE = 'duplicate';
    public const RETRY_SENT = 'retry_sent';
    public const RETRY_DELAYED = 'retry_delayed';
    public const RETRY_EXHAUSTED = 'retry_exhausted';

      private $status;
      private $retryAttempt;
      private $nextAllowedAt;

    public function __construct(string $status, int $retryAttempt = 0, int $nextAllowedAt = 0)
    {
        if (!in_array($status, [self::COMMITTED, self::DUPLICATE, self::RETRY_SENT, self::RETRY_DELAYED, self::RETRY_EXHAUSTED], true)
            || $retryAttempt < 0 || $nextAllowedAt < 0) {
            throw new InvalidArgumentException('Incoming message result is invalid.');
        }
        $this->status = $status; $this->retryAttempt = $retryAttempt; $this->nextAllowedAt = $nextAllowedAt;
    }
    public function status(): string { return $this->status; }
    public function retryAttempt(): int { return $this->retryAttempt; }
    public function nextAllowedAt(): int { return $this->nextAllowedAt; }
    public function wasCommitted(): bool { return $this->status === self::COMMITTED || $this->status === self::DUPLICATE; }
}
