storage = $storage; $this->templateStorage = $templateStorage; $this->workflowValidator = $workflowValidator; } public function createWorkflow(string $slug): Workflow { $template = $this->templateStorage->getTemplateBySlug($slug); if (!$template) { throw UnexpectedValueException::create()->withMessage('Template not found.'); } $workflow = $template->getWorkflow(); $this->workflowValidator->validate($workflow); $workflowId = $this->storage->createWorkflow($workflow); $savedWorkflow = $this->storage->getWorkflow($workflowId); if (!$savedWorkflow) { throw new InvalidStateException('Workflow not found.'); } return $savedWorkflow; } }