import { defHttp } from '/@/utils/http/axios';
import { PageParams, deleteParams, addParams, cameraListParams, companyExcelParams } from './model';
import { Result, FileStream, UploadFileParams } from '/#/axios';

enum Api {
  companyList = '/service/manage/company/list',
  companyAdd = '/service/manage/company/add',
  companyUpdate = '/service/manage/company/update',
  companyDelete = '/service/manage/company/delete',
  cameraList = '/service/agent/camera/list',
  companyUploadExcel = '/service/manage/excel/uploadExcel',
  downTemplate = '/service/manage/excel/downTemplate',
}

export const companyList = (params: PageParams) =>
  defHttp.post<Result>({
    url: Api.companyList,
    params: params,
    // data: params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
export const companyAdd = (params: addParams) =>
  defHttp.post<Result>({
    url: Api.companyAdd,
    params: params,
    // data: params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
export const companyUpdate = (params: addParams) =>
  defHttp.post<Result>({
    url: Api.companyUpdate,
    params: params,
    // data: params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
export const companyDelete = (params: deleteParams) =>
  defHttp.post<Result>({
    url: Api.companyDelete,
    params: params,
    // data: params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
export const cameraList = (params: cameraListParams) =>
  defHttp.post<Result>({
    url: Api.cameraList,
    params: params,
    // data: params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
export const downTemplate = (params: companyExcelParams) =>
  defHttp.downloadFile<FileStream>({
    method: 'GET',
    url: Api.downTemplate,
    params: params,
    // data: params, 
    fileName:params.type == 0?'入库模板.xlsx':params.type == 1?'出库模板.xlsx':'客户关联模板.xlsx',
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
    responseType: 'blob'
  });

export function companyUploadExcel(
    params: UploadFileParams,
    onUploadProgress: (progressEvent: ProgressEvent) => void,
  ) {
    return defHttp.uploadFile<Result>(
      {
        url: Api.companyUploadExcel,
        onUploadProgress,
      },
      params,
    );
   }
