import Request from '../..'

enum Api {
  UserCreate = '/workspace/user/create',
  UserList = '/workspace/user/page',
  UserBase = '/workspace/user',
  ResetPassword = '/workspace/user/pwd/reset',
  UserInfo = '/workspace/user/info',
  UserDel = '/workspace/user/del',
  UserDetail = '/workspace/user/details',
  UserUpdate = '/workspace/user/update',
  ResetPasswordAdmin = '/workspace/user/password/renew'
}

// 获取用户管理列表
export function getUserListPage(query: API.PageParams<{ username: string; deptId: number }>) {
  return Request.get<API.TableListResult<API.UserListPageResult>>({
    url: Api.UserList,
    params: query
  })
}

// 重置密码
export function pwdReset(data: { userId: number; username: string }) {
  return Request.put({
    url: Api.ResetPassword,
    data
  })
}

// 删除用户
export function deleteUser(userId: number) {
  return Request.post({
    url: Api.UserDel,
    data: { userIds: [userId], deleteType: 'SOFT' }
  })
}

// 新增用户
export function addUser(data: API.AddUserParams) {
  return Request.post({
    url: Api.UserCreate,
    data
  })
}

// 更新用户
export function updateUser(data: API.UserParams) {
  return Request.post({
    url: Api.UserUpdate,
    data
  })
}

// 重置密码(管理员重置)
export function pwdResetAdmin(data: { userId: number | string; password: string }) {
  return Request.post({
    url: Api.ResetPasswordAdmin,
    data
  })
}

// 获取用户信息
export function getUserInfo() {
  return Request.get<API.UserInfo>({
    url: Api.UserInfo
  })
}

// 通过ID查询角色信息
export function getUserDetail(id: number) {
  return Request.get<API.UserDetail>({
    url: Api.UserDetail + `/${id}`
  })
}
