name); $steps = $this->stepBuilder->build($data->steps); $template = WorkflowTemplate::create($data->workTypeId, $name, $steps); return $this->transactions->run(function () use ($data, $name, $steps, $template): int { $workType = $this->workTypes->findById($data->workTypeId); if ($workType === null || ! $workType->isActive()) { throw new CatalogItemNotFound(CatalogLevel::WorkType, $data->workTypeId); } if ($this->templates->isNameTaken($data->workTypeId, $name->value)) { throw new WorkflowTemplateNameTaken; } $this->stepBuilder->checkWorkTypes($workType, $steps); return (int) $this->templates->save($template)->id(); }); } }