import { defHttp } from '/@/utils/http/axios';
import { Result, FileStream, UploadFileParams } from '/#/axios';

enum Api {
  listApi = '/service/agent/agentManage/list',
  addApi = '/service/agent/agentManage/add',
  updateApi = '/service/agent/agentManage/update',
  addIncrementNum = '/service/agent/agentManage/addIncrementNum',
  banOrUnBan = '/service/agent/agentManage/banOrUnBan',
  giveCamera = '/service/agent/camera/giveCamera',
  giveCameraBatch = '/service/agent/camera/giveCameraBatch',
  checkUserName = '/service/agent/agentManage/checkUserName',
  getSubAgent = '/service/agent/agentManage/getSubAgent',
  downTemplate = '/service/agent/camera/downTemplate',
}

export const listApi = (params) =>
  defHttp.post<Result>({
    url: Api.listApi,
    params: params,
    // data: params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
export const addApi = (params) =>
  defHttp.post<Result>({
    url: Api.addApi,
    params: params,
    // data: params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
export const addIncrementNum = (params) =>
  defHttp.post<Result>({
    url: Api.addIncrementNum,
    params: params,
    // data: params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
export const giveCamera = (params) =>
  defHttp.post<Result>({
    url: Api.giveCamera,
    params: params,
    // data: params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
export const updateApi = (params) =>
  defHttp.post<Result>({
    url: Api.updateApi,
    params: params,
    // data: params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
export const banOrUnBan = (params) =>
  defHttp.post<Result>({
    url: Api.banOrUnBan,
    params: params,
    // data: params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

export const getSubAgent = (params) =>
  defHttp.get<Result>({
    url: Api.getSubAgent,
    params,
    data: params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

export const downTemplate = (params) =>
  defHttp.downloadFile<FileStream>({
    method: 'GET',
    url: Api.downTemplate,
    params: params,
    // data: params,
    fileName: params.filename,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
    responseType: 'blob',
  });

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