import { UploadApiResult } from './model/uploadModel';
import { defHttp } from '@/utils/http/axios';
import { UploadFileParams } from '#/axios';
import { useGlobSetting } from '@/hooks/setting';
import { AxiosProgressEvent } from 'axios';

const { uploadUrl } = useGlobSetting();

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

export function fileUploadApi(
  params: UploadFileParams,
  url: string,
  onUploadProgress: (progressEvent: AxiosProgressEvent) => void,
) {
  return defHttp.uploadFile<UploadApiResult>(
    {
      url: url,
      onUploadProgress,
    },
    params,
  );
}
