|null $groupIds Null: the whole stock. */ private function __construct( private ?int $id, private DateTimeImmutable $countedOn, private ?array $groupIds, private int $startedBy, private ?int $confirmedBy, private ?DateTimeImmutable $confirmedAt, private ?int $valueBeforeCents, private ?int $valueAfterCents, ) {} /** * @param list|null $groupIds */ public static function start(DateTimeImmutable $countedOn, ?array $groupIds, int $startedBy): self { return new self(null, $countedOn, $groupIds === [] ? null : $groupIds, $startedBy, null, null, null, null); } /** * @param list|null $groupIds */ public static function reconstitute(int $id, DateTimeImmutable $countedOn, ?array $groupIds, int $startedBy, ?int $confirmedBy, ?DateTimeImmutable $confirmedAt, ?int $valueBeforeCents, ?int $valueAfterCents): self { return new self($id, $countedOn, $groupIds, $startedBy, $confirmedBy, $confirmedAt, $valueBeforeCents, $valueAfterCents); } /** * @throws InventoryCountConfirmed */ public function ensureOpen(): void { if ($this->isConfirmed()) { throw new InventoryCountConfirmed; } } /** * @throws InventoryCountConfirmed */ public function confirm(int $userId, DateTimeImmutable $at, int $valueBeforeCents, int $valueAfterCents): void { $this->ensureOpen(); $this->confirmedBy = $userId; $this->confirmedAt = $at; $this->valueBeforeCents = $valueBeforeCents; $this->valueAfterCents = $valueAfterCents; } public function covers(int $groupId): bool { return $this->groupIds === null || in_array($groupId, $this->groupIds, true); } public function isConfirmed(): bool { return $this->confirmedAt !== null; } public function id(): ?int { return $this->id; } public function countedOn(): DateTimeImmutable { return $this->countedOn; } /** * @return list|null */ public function groupIds(): ?array { return $this->groupIds; } public function startedBy(): int { return $this->startedBy; } public function confirmedBy(): ?int { return $this->confirmedBy; } public function confirmedAt(): ?DateTimeImmutable { return $this->confirmedAt; } public function valueBeforeCents(): ?int { return $this->valueBeforeCents; } public function valueAfterCents(): ?int { return $this->valueAfterCents; } }