/**
 * 模板相关 API
 * Phase 1 新增：全局模板库
 */
import apiClient from "./client";

/** 模板条目 */
export interface TemplateItem {
  id: string;
  name: string;
  description: string;
  category: string;
  target_duration: number;
  clip_count: number;
  thumbnail_url?: string;
  preview_url?: string;
  is_active: boolean;
  is_favorite?: boolean;
  created_at?: string;
}

/** 获取全局模板列表 */
export const getTemplates = async (): Promise<TemplateItem[]> => {
  const response = await apiClient.get("/templates");
  return response.data.items || response.data || [];
};

/** 获取单个模板详情 */
export const getTemplate = async (
  templateId: string,
): Promise<TemplateItem> => {
  const response = await apiClient.get(`/templates/${templateId}`);
  return response.data;
};

/** 收藏 / 取消收藏模板 */
export const toggleFavoriteTemplate = async (
  templateId: string,
): Promise<{ is_favorite: boolean }> => {
  const response = await apiClient.post(
    `/templates/${templateId}/toggle-favorite`,
  );
  return response.data;
};
