import request from '@/utils/request';

// 初始化分片上传
export function initMultipartUpload(fileName: string, fileSize: number) {
  return request({
    url: '/system/oss/multipart/init',
    method: 'post',
    params: {
      fileName,
      fileSize
    }
  });
}

// 上传分片
export function uploadPart(uploadId: string, partNumber: number, formData: FormData) {
  return request({
    url: '/system/oss/multipart/uploadPart',
    method: 'post',
    data: formData,
    params: {
      uploadId,
      partNumber
    },
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}

// 完成分片上传
export function completeMultipartUpload(
  uploadId: string, 
  partETags: string, 
  fileName: string, 
  originalName: string
) {
  return request({
    url: '/system/oss/multipart/complete',
    method: 'post',
    params: {
      uploadId,
      partETags,
      fileName,
      originalName
    }
  });
}

// 取消分片上传
export function abortMultipartUpload(uploadId: string) {
  return request({
    url: '/system/oss/multipart/abort',
    method: 'post',
    params: {
      uploadId
    }
  });
}

// 检查已上传的分片
export function checkUploadedParts(uploadId: string) {
  return request({
    url: '/system/oss/multipart/checkParts',
    method: 'get',
    params: {
      uploadId
    }
  });
}
