/**
 * 成品相关 API
 * Phase 1 重构：去掉 projectId，成品直接归属用户
 */
import apiClient from "./client";

/** 成品条目 */
export interface ProductItem {
  id: string;
  title: string;
  video_url?: string;
  thumbnail_url?: string;
  duration_seconds?: number;
  file_size?: number;
  resolution?: string;
  status: "processing" | "completed" | "failed";
  /** 查重率（百分比） */
  duplicate_rate?: number;
  created_at?: string;
  updated_at?: string;
}

/** 获取当前用户的所有成品 */
export const getProducts = async (): Promise<ProductItem[]> => {
  const response = await apiClient.get("/products");
  return response.data.items || response.data || [];
};

/** 获取单个成品详情 */
export const getProduct = async (productId: string): Promise<ProductItem> => {
  const response = await apiClient.get(`/products/${productId}`);
  return response.data;
};

/** 删除成品 */
export const deleteProduct = async (productId: string): Promise<void> => {
  await apiClient.delete(`/products/${productId}`);
};

/** 获取成品下载链接 */
export const getProductDownloadUrl = async (
  productId: string,
): Promise<{ url: string; expires_at: string }> => {
  const response = await apiClient.get(`/products/${productId}/download-url`);
  return response.data;
};
