<?php

declare(strict_types=1);

namespace PhpWA\Runtime;

use InvalidArgumentException;

final class AppStateJobRunResult
{
      private $jobs;
      private $pages;
      private $mutations;
      private $failed;
      private $deadLettered;
      private $lastError;

    public function __construct(int $jobs, int $pages, int $mutations, int $failed, int $deadLettered, ?string $lastError)
    {
        if ($jobs < 0 || $pages < 0 || $mutations < 0 || $failed < 0 || $deadLettered < 0
            || ($lastError !== null && preg_match('/\A[a-z][a-z0-9_]{0,63}\z/D', $lastError) !== 1)) {
            throw new InvalidArgumentException('App-state job run result is invalid.');
        }
        $this->jobs = $jobs; $this->pages = $pages; $this->mutations = $mutations;
        $this->failed = $failed; $this->deadLettered = $deadLettered; $this->lastError = $lastError;
    }

    public function jobs(): int { return $this->jobs; }
    public function pages(): int { return $this->pages; }
    public function mutations(): int { return $this->mutations; }
    public function failed(): int { return $this->failed; }
    public function deadLettered(): int { return $this->deadLettered; }
     
    public function lastErrorCode(): ?string { return $this->lastError; }
     
    public function lastError(): ?string { return $this->lastError; }
}
