<?php

declare(strict_types=1);

namespace PhpWA\Runtime;

use InvalidArgumentException;
use PhpWA\Client\SessionEvent;

final class WorkerRunResult
{
      private $lockAcquired;
      private $nodes;
      private $replayed;
      private $state;
      private $events;

     
    public function __construct(bool $lockAcquired, int $nodes, int $replayed, string $state, array $events)
    {
        if ($nodes < 0 || $replayed < 0 || $state === '') { throw new InvalidArgumentException('Worker run result is invalid.'); }
        foreach ($events as $event) { if (!$event instanceof SessionEvent) { throw new InvalidArgumentException('Worker run events are invalid.'); } }
        $this->lockAcquired = $lockAcquired; $this->nodes = $nodes; $this->replayed = $replayed;
        $this->state = $state; $this->events = array_values($events);
    }

    public static function busy(): self { return new self(false, 0, 0, 'busy', []); }
    public function lockAcquired(): bool { return $this->lockAcquired; }
    public function nodesProcessed(): int { return $this->nodes; }
    public function stanzasReplayed(): int { return $this->replayed; }
    public function state(): string { return $this->state; }
      public function events(): array { return $this->events; }
}
