<?php

declare(strict_types=1);

namespace PhpWA\Client;

use InvalidArgumentException;

final class HistorySyncRunResult
{
      private $hadJob;
      private $complete;
      private $eventsStaged;
      private $nextCursor;

    public function __construct(bool $hadJob, bool $complete, int $eventsStaged, int $nextCursor)
    {
        if ($eventsStaged < 0 || $nextCursor < 0 || (!$hadJob && ($complete || $eventsStaged !== 0 || $nextCursor !== 0))) {
            throw new InvalidArgumentException('History-sync run result is invalid.');
        }
        $this->hadJob = $hadJob; $this->complete = $complete;
        $this->eventsStaged = $eventsStaged; $this->nextCursor = $nextCursor;
    }

    public static function idle(): self { return new self(false, false, 0, 0); }
    public function hadJob(): bool { return $this->hadJob; }
    public function isComplete(): bool { return $this->complete; }
    public function eventsStaged(): int { return $this->eventsStaged; }
    public function nextCursor(): int { return $this->nextCursor; }
}
