*/ public array $items = []; private int $nextId = 1; public function findById(int $id): ?WorkflowTemplate { return isset($this->items[$id]) ? clone $this->items[$id] : null; } public function save(WorkflowTemplate $template): WorkflowTemplate { $id = $template->id() ?? $this->nextId++; $this->items[$id] = WorkflowTemplate::reconstitute($id, $template->workTypeId(), $template->name(), $template->isActive(), $template->steps()); return clone $this->items[$id]; } public function isNameTaken(int $workTypeId, string $name, ?int $exceptId = null): bool { foreach ($this->items as $id => $template) { if ($id !== $exceptId && $template->workTypeId() === $workTypeId && mb_strtolower($template->name()->value) === mb_strtolower($name)) { return true; } } return false; } }