storage = $storage; $this->automationValidator = $automationValidator; $this->registry = $registry; } public function createAutomation(string $slug): Automation { $template = $this->registry->getTemplate($slug); if (!$template) { throw Exceptions::automationTemplateNotFound($slug); } $automation = $template->createAutomation(); $this->automationValidator->validate($automation); $automationId = $this->storage->createAutomation($automation); $savedAutomation = $this->storage->getAutomation($automationId); if (!$savedAutomation) { throw new InvalidStateException('Automation not found.'); } return $savedAutomation; } }