import { api } from './http';

export interface PromptTemplate {
  id: string;
  ownerId: string;
  ownerName?: string;
  title: string;
  body: string;
  category: string;
  variables: string;
  visibility: 'private' | 'public';
  useCount: number;
  createdAt: number;
  updatedAt: number;
}

export const PromptTemplateAPI = {
  list: (opts: { scope?: 'mine' | 'public' | 'all'; q?: string } = {}) =>
    api
      .get<PromptTemplate[]>('/prompt-templates', {
        params: { scope: opts.scope ?? 'all', q: opts.q ?? '' }
      })
      .then((r) => r.data),
  create: (payload: Partial<PromptTemplate>) => api.post<{ id: string }>('/prompt-templates', payload).then((r) => r.data),
  update: (id: string, payload: Partial<PromptTemplate>) => api.put(`/prompt-templates/${id}`, payload).then((r) => r.data),
  remove: (id: string) => api.delete(`/prompt-templates/${id}`).then((r) => r.data),
  use: (id: string) => api.post(`/prompt-templates/${id}/use`).then((r) => r.data)
};

