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