import { fetchWithAuth } from "./client"; // ── 类型定义 ──────────────────────────────────────────────────────────────────── export type ContentStatus = | "draft" | "review" | "approved" | "published" | "archived"; export type ContentType = | "article" | "qa" | "knowledge_base" | "social_post" | "other"; export interface Content { id: string; title: string; body: string; content_type: ContentType; status: ContentStatus; project_id?: string; author_id: string; tags?: string[]; created_at: string; updated_at: string; published_at?: string; } export interface KnowledgeEntry { id: string; brand_id: string; category: string; title: string; body: string; source?: string; created_at: string; updated_at: string; } export interface CreateContentPayload { title: string; body: string; content_type: ContentType; project_id?: string; tags?: string[]; } export interface UpdateContentPayload { title?: string; body?: string; content_type?: ContentType; status?: ContentStatus; tags?: string[]; } // ── API ──────────────────────────────────────────────────────────────────────── export const contentsApi = { list: (token?: string, params?: string) => fetchWithAuth( `/api/v1/contents/${params ? `?${params}` : ""}`, {}, token ) as Promise, get: (token?: string, contentId?: string) => fetchWithAuth( `/api/v1/contents/${contentId}`, {}, token ) as Promise, create: (token?: string, data?: CreateContentPayload) => fetchWithAuth( "/api/v1/contents/", { method: "POST", body: JSON.stringify(data) }, token ) as Promise, update: (token?: string, contentId?: string, data?: UpdateContentPayload) => fetchWithAuth( `/api/v1/contents/${contentId}`, { method: "PUT", body: JSON.stringify(data) }, token ) as Promise, delete: (token?: string, contentId?: string) => fetchWithAuth(`/api/v1/contents/${contentId}`, { method: "DELETE" }, token), publish: (token?: string, contentId?: string) => fetchWithAuth( `/api/v1/contents/${contentId}/publish`, { method: "POST" }, token ) as Promise, // 品牌知识库 listKnowledge: (token?: string, brandId?: string) => fetchWithAuth( `/api/v1/contents/knowledge/${brandId ? `?brand_id=${brandId}` : ""}`, {}, token ) as Promise, createKnowledge: ( token?: string, data?: Omit ) => fetchWithAuth( "/api/v1/contents/knowledge/", { method: "POST", body: JSON.stringify(data) }, token ) as Promise, updateKnowledge: ( token?: string, knowledgeId?: string, data?: Partial> ) => fetchWithAuth( `/api/v1/contents/knowledge/${knowledgeId}`, { method: "PUT", body: JSON.stringify(data) }, token ) as Promise, deleteKnowledge: (token?: string, knowledgeId?: string) => fetchWithAuth( `/api/v1/contents/knowledge/${knowledgeId}`, { method: "DELETE" }, token ), };