/** * Template Service - CRUD operations via Backend API */ import { templateApi, type Template as ApiTemplate } from './api'; // Re-export type with backwards-compatible naming (snake_case for mobile) export interface Template { id: string; user_id: string; name: string; description: string | null; system_prompt: string; initial_question: string | null; model_id: string | null; color: string; is_default: boolean; document_mode: boolean; created_at: string; updated_at: string; } // Helper to convert API response to local format function toLocalTemplate(template: ApiTemplate): Template { return { id: template.id, user_id: template.userId, name: template.name, description: template.description || null, system_prompt: template.systemPrompt, initial_question: template.initialQuestion || null, model_id: template.modelId || null, color: template.color, is_default: template.isDefault, document_mode: template.documentMode, created_at: template.createdAt, updated_at: template.updatedAt, }; } /** * Lädt alle Vorlagen eines Benutzers */ export async function getTemplates(userId: string): Promise { try { const templates = await templateApi.getTemplates(); return templates.map(toLocalTemplate); } catch (error) { console.error('Fehler beim Laden der Vorlagen:', error); return []; } } /** * Lädt eine bestimmte Vorlage anhand ihrer ID */ export async function getTemplateById(templateId: string): Promise