<?php

declare(strict_types=1);

namespace PhpWA\Runtime;

use InvalidArgumentException;

final class OutboxRunResult
{
      private $delivered;
      private $failed;
      private $deadLettered;
      private $lastError;

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

    public function delivered(): int { return $this->delivered; }
    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; }
}
