import type { AxiosProgressEvent } from 'axios'
import type { UploadApiResult, UploadFullApiResult } from './model/uploadModel'
import { defHttp } from '@/utils/http/axios'
import type { FileDO, UploadFileParams } from '@/types/axios'
import { useGlobSetting } from '@/hooks/setting'

const { uploadUrl = '', uploadUrlFull } = useGlobSetting()

/**
 * @description: Upload interface
 */
export function uploadApi(params: UploadFileParams, onUploadProgress: (progressEvent: AxiosProgressEvent) => void) {
  return defHttp.uploadFile<UploadApiResult>(
    {
      url: uploadUrl,
      onUploadProgress,
    },
    params,
  )
}

export function uploadOneFile(params: UploadFileParams) {
  return defHttp.uploadFile<UploadFullApiResult<FileDO>>(
    {
      url: uploadUrlFull,
    },
    params,
  )
}
