import { defHttp } from '/@/utils/http/axios';
import { PageParams, ListGetResultModel, DelParams, roleParams } from './model';
import { Result } from '/#/axios';
import { encodeStr } from '/@/utils/encodeUtil';

enum Api {
  pageList = '/service/sale/sysUser/list',
  userList = '/service/sale/sysUser/allList',
  sysUserAdd = '/service/sale/sysUser/add',
  updatePassword = '/service/sale/sysUser/rePassword',
  preDel = '/service/sale/sysUser/delete',
  roleList = '/zfb-api/zfb/shop/sys/user/roleList',
  getRoleListByParam = '/service/sale/sysRole/allList',
  staffSave = '/service/sale/sysUser/add',
  update = '/service/sale/sysUser/update',
  checkUser = '/zfb-api/zfb/user/checkUserExists',
  deleteStaff = '/service/sale/sysUser/delete',
  getNumByStaff = '/zfb-api/zfb/shop/sys/user/getNumByStaff',
  clean = '/zfb-api/zfb/loginOutByUser',
}

/**
 * @description: Get sample list value
 */

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

export function updatePasswordApi(params) {
    return defHttp.post<Result>(
      { url: Api.updatePassword, params },
      // { errorMessageMode: 'none' },
    );
} 
export const staffListApi = (params: PageParams) =>
  defHttp.post<ListGetResultModel>({
    url: Api.pageList,
    params,
    data: params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

export const ListApi = (params: PageParams) =>
  defHttp.post<ListGetResultModel>({
    url: Api.pageList,
    params,
    data: params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

export const getNumByStaff = (params: any) =>
  defHttp.get<Result>({
    url: Api.getNumByStaff,
    params,
    data: params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
export const delApi = (params: DelParams) =>
  defHttp.post<Result>({
    url: Api.deleteStaff,
    params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
export const preDelApi = (params: number) =>
  defHttp.post<Result>({
    url: Api.preDel,
    params: { id: params },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
export const getRoleListByParam = (params: roleParams) =>
  defHttp.get<Result>({
    url: Api.getRoleListByParam,
    params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
export const roleLIstApi = (params) =>
  defHttp.post<Result>({
    url: Api.roleList,
    params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
export const checkUserApi = (params) =>
  defHttp.post<boolean>({
    url: Api.checkUser,
    params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

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

export const saveApi = (params) =>
defHttp.post<Result>({
  url: Api.staffSave,
  params:{
      ...params,
      // password: encodeStr(window.btoa(params.password))
  },
  headers: {
    // @ts-ignore
    ignoreCancelToken: true,
  },
});
export const updateApi = (params) =>
  defHttp.post<Result>({
    url: Api.update,
    params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
