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

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/agent/camera/downTemplate',
  cameraExport = '/service/agent/camera/export',
  uploadAuthModelExcel = '/service/agent/authorizeModeling/uploadAuthModelExcel',
}

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) => {
  const { t } = useI18n();
  const fileName = {
    0: '批量分发.xlsx',
    1: t('routes.empower.pldr') + '.xlsx',
    2: '客户关联模板.xlsx',
    3: '入库模板.xlsx',
  };
  return defHttp.downloadFile<FileStream>({
    method: 'GET',
    url: Api.downTemplate,
    params: params,
    fileName: fileName[params.type] || '客户关联模板.xlsx',
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
    responseType: 'blob',
  });
};
export const downCameraExport = (params: companyExcelParams) => {
  const { t } = useI18n();
  return defHttp.downloadFile<FileStream>({
    method: 'GET',
    url: Api.cameraExport,
    params: params,
    fileName: t('routes.dashboard.devices') + '.xlsx',
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
    responseType: 'blob',
  });
};

//导入算法授权授权时间

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

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