import request from '@/config/axios';
import type { TableData } from './types';

/** 获取表格数据 */
export const getSysUserListApi = (data: any) => {
  return request.postJson({ url: '/system/spi/system/SysUser/SysUserQueryPage', data });
};

/** 批量删除 */
export const delSysUserListApi = (list: string[] | number[]): Promise<IResponse> => {
  const _list = list.map(v => {
    return {
      id: v,
    };
  });
  return request.postJson({
    url: '/system/spi/system/SysUser/SysUserBatchDelete',
    data: {
      list: _list,
    },
  });
};

/** 删除 */
export const delSysUserApi = (id: string | number): Promise<IResponse> => {
  return request.postJson({ url: '/system/spi/system/SysUser/SysUserDelete', data: { id } });
};

/** 保存 */
export const saveSysUserApi = (data: Partial<TableData>): Promise<IResponse> => {
  return request.postJson({ url: '/system/spi/system/SysUser/SysUserSave', data });
};

/** 查询单条数据 */
export const querySysUserApi = (id: string | number): Promise<IResponse> => {
  return request.postJson({ url: '/system/spi/system/SysUser/SysUserQueryOne', data: { id } });
};

/** 导入 */
export const importExcelApiUrl = '/system/sui/system/SysUser/SysUserImportExcel';

/** 导出 */
export const exportExcelApi = (params: any) => {
  return request.doExport({ url: '/system/sdi/system/SysUser/SysUserExportXls', params });
};

/** 机构树 */
export const organTreeApi = (params: any) => {
  return request.postJson({ url: '/param/spi/param/systemorgantree', params });
};

/** 重置密码 */
export const resetPasswordbatch = (params: { list: { id: string }[] }) => {
  return request.postJson({
    url: '/system/spi/system/SysUser/SysUserBatchChangePassword',
    data: params,
  });
};

/** 更改用户状态 */
export const batchUpdateUser = (params: { list: { ids: string[]; status: '0' | '1' | '2' } }) => {
  return request.postJson({ url: '/system/spi/system/SysUser/SysUseBatchUpdate', data: params });
};

/** 获取角色列表接口 */
export const getRoleListParamsApi = (): Promise<IResponse> => {
  return request.postJson({ url: '/system/spi/system/SysRole/SysRoleQuery' });
};

export const updatePasswordApi = (data: Partial<TableData>): Promise<IResponse> => {
  return request.postJson({ url: '/system/spi/system/SysUser/SysUserChangePassword', data });
};
