import httpClient from '@/utils/http';

import {
  ControllerResponse,
  FileServiceFileInfoVO,
  ModelCreateDownloadSessionRequest,
  ModelCreateUploadSessionRequest,
  ModelFileDownloadSession,
  ModelFileUploadSession,
  ServiceUploadProgress
} from './data-contracts';
export default {
  /**
   * @description 取消文件上传会话，清理已上传的切片
   */
  chunkCancelCreate: (session_id: string) => {
    return httpClient.post<
      ControllerResponse & {
        message?: string;
      }
    >(`/files/chunk/cancel`, { params: session_id });
  },
  /**
   * @description 创建文件分片下载会话
   */
  chunkCreateDownloadSessionCreate: (request: ModelCreateDownloadSessionRequest) => {
    return httpClient.post<
      ControllerResponse & {
        data?: ModelFileDownloadSession;
      }
    >(`/files/chunk/create-download-session`, { params: request });
  },
  /**
   * @description 创建文件分片上传会话，返回会话ID
   */
  chunkCreateSessionCreate: (request: ModelCreateUploadSessionRequest) => {
    return httpClient.post<
      ControllerResponse & {
        data?: ModelFileUploadSession;
      }
    >(`/files/chunk/create-session`, { params: request });
  },
  /**
   * @description 下载单个文件切片
   */
  chunkDownloadList: (query: {
    /** 会话ID */
    session_id: string;
    /** 切片索引 */
    chunk_index: number;
  }) => {
    return httpClient.download<Blob>(`/files/chunk/download`, { query: query });
  },
  /**
   * @description 合并所有已上传的切片，生成完整文件
   */
  chunkMergeCreate: (session_id: string) => {
    return httpClient.post<
      ControllerResponse & {
        data?: FileServiceFileInfoVO;
      }
    >(`/files/chunk/merge`, { params: session_id });
  },
  /**
   * @description 获取文件分片上传进度
   */
  chunkProgressList: (query: {
    /** 会话ID */
    session_id: string;
  }) => {
    return httpClient.get<
      ControllerResponse & {
        data?: ServiceUploadProgress;
      }
    >(`/files/chunk/progress`, { query: query });
  },
  /**
   * @description 恢复中断的文件上传，返回已上传的切片信息
   */
  chunkResumeList: (query: {
    /** 会话ID */
    session_id: string;
  }) => {
    return httpClient.get<
      ControllerResponse & {
        data?: ServiceUploadProgress;
      }
    >(`/files/chunk/resume`, { query: query });
  },
  /**
   * @description 上传单个文件切片
   */
  chunkUploadCreate: (data: {
    /** 会话ID */
    session_id: string;
    /** 切片索引 */
    chunk_index: number;
    /**
     * 切片文件
     * @format binary
     */
    chunk: File;
  }) => {
    return httpClient.formData<
      ControllerResponse & {
        message?: string;
      }
    >(`/files/chunk/upload`, { params: data });
  }
};
