<?php

declare(strict_types=1);

namespace PhpWA\AppState;

use InvalidArgumentException;

final class AppStateApplyResult
{
    /** @var string */ private $name;
    /** @var int */ private $version;
    /** @var int */ private $mutations;
    /** @var bool */ private $duplicate;

    public function __construct(string $name, int $version, int $mutations, bool $duplicate)
    {
        AppStateName::assert($name);
        if ($version < 0 || $mutations < 0) { throw new InvalidArgumentException('App-state apply result is invalid.'); }
        $this->name = $name; $this->version = $version; $this->mutations = $mutations; $this->duplicate = $duplicate;
    }

    public function name(): string { return $this->name; }
    public function version(): int { return $this->version; }
    public function mutations(): int { return $this->mutations; }
    public function isDuplicate(): bool { return $this->duplicate; }
}
