/**
 * @description 文件上传相关API
 * @author yslg
 * @since 2025-10-15
 */

import { api } from '@/apis/index';
import type { AiUploadFile, FileUploadResponse, ResultDomain } from '@/types';

/**
 * 文件上传API服务
 */
export const fileUploadApi = {
  /**
   * 上传文件
   * @param file 文件
   * @param userID 用户ID
   * @returns Promise<ResultDomain<FileUploadResponse>>
   */
  async uploadFile(file: File, userID: string): Promise<ResultDomain<FileUploadResponse>> {
    const formData = new FormData();
    formData.append('file', file);
    formData.append('userID', userID);
    
    const response = await api.upload<FileUploadResponse>('/ai/file/upload', formData);
    return response.data;
  },

  /**
   * 获取上传文件列表
   * @param userID 用户ID
   * @returns Promise<ResultDomain<AiUploadFile>>
   */
  async getUploadFileList(userID: string): Promise<ResultDomain<AiUploadFile>> {
    const response = await api.get<AiUploadFile>('/ai/file/list', { userID });
    return response.data;
  },

  /**
   * 删除上传文件
   * @param fileID 文件ID
   * @returns Promise<ResultDomain<boolean>>
   */
  async deleteUploadFile(fileID: string): Promise<ResultDomain<boolean>> {
    const response = await api.delete<boolean>(`/ai/file/${fileID}`);
    return response.data;
  }
};
