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/manage/sysUser/list',
  sysUserAdd = '/service/manage/sysUser/add',
  updatePassword = '/service/manage/sysUser/rePassword',
  reMyselfPassword = '/service/manage/sysUser/reMyselfPassword',
  preDel = '/service/manage/sysUser/delete',
  roleList = '/zfb-api/zfb/shop/sys/user/roleList',
  getRoleListByParam = '/service/manage/sysRole/allList',
  staffSave = '/service/manage/sysUser/add',
  update = '/service/manage/sysUser/update',
  checkUser = '/zfb-api/zfb/user/checkUserExists',
  deleteStaff = '/zfb-api/zfb/shop/sys/user/deleteStaff',
  getNumByStaff = '/zfb-api/zfb/shop/sys/user/getNumByStaff',
  clean = '/zfb-api/zfb/loginOutByUser',

  addUcenterUser = '/service/manage/user/addUcenterUser',
  ReUcenterUserPassword = '/service/manage/user/ReUcenterUserPassword',
  delUcenterUser = '/service/manage/user/delUcenterUser',
  updateUcenterUser = '/service/manage/user/updateUcenterUser'
}

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

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

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

export function reMyselfPassword(params) {
  return defHttp.post<Result>(
    { url: Api.reMyselfPassword, 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 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,
    },
  });
