promptsRepo = $promptsRepo ?? new PromptsRepository(); } public function getAll(): array { return array_map( fn (array $row) => PromptDTO::fromArray($row), $this->promptsRepo->findAll() ); } public function getById(int $id): ?PromptDTO { $data = $this->promptsRepo->findById($id); return $data !== null ? PromptDTO::fromArray($data) : null; } public function getActivePrompts(): array { return $this->promptsRepo->findActivePrompts(); } public function create( string $name, string $version, string $content, bool $isActive ): PromptResult { $name = trim($name); $content = trim($content); if ($name === '' || $content === '') { return PromptResult::error('Name und Inhalt sind erforderlich.'); } $id = $this->promptsRepo->create($name, $version, $content, $isActive ? 1 : 0); return PromptResult::success($id, 'Prompt erfolgreich erstellt.'); } public function update( int $id, string $name, string $version, string $content, bool $isActive ): PromptResult { $name = trim($name); $content = trim($content); if ($name === '' || $content === '') { return PromptResult::error('Name und Inhalt sind erforderlich.'); } $existing = $this->promptsRepo->findById($id); if ($existing === null) { return PromptResult::error('Prompt nicht gefunden.'); } $this->promptsRepo->update($id, $name, $version, $content, $isActive ? 1 : 0); return PromptResult::success($id, 'Prompt aktualisiert.'); } public function delete(int $id): PromptResult { $existing = $this->promptsRepo->findById($id); if ($existing === null) { return PromptResult::error('Prompt nicht gefunden.'); } $criticCount = $this->promptsRepo->countLinkedCritics($id); if ($criticCount > 0) { return PromptResult::error("Kann nicht gelöscht werden: {$criticCount} Critics verknüpft."); } $this->promptsRepo->delete($id); return PromptResult::success($id, 'Prompt gelöscht.'); } public function duplicate(int $id): PromptResult { $existing = $this->promptsRepo->findById($id); if ($existing === null) { return PromptResult::error('Prompt nicht gefunden.'); } $newName = $existing['name'] . ' (Kopie)'; $newId = $this->promptsRepo->duplicate($id, $newName, '1.0'); return PromptResult::success($newId, 'Prompt dupliziert.'); } public function getLinkedCritics(int $promptId): array { return $this->promptsRepo->findLinkedCritics($promptId); } public function getStatistics(): array { return $this->promptsRepo->getStatistics(); } }