import { request } from '@/service/request';

// 获取用户列表
/** get user list */
export function fetchGetUserList(params?: Api.SystemManage.UserSearchParams) {
  return request<Api.SystemManage.UserList>({
    url: '/system/user/list',
    method: 'get',
    params
  });
}
// 获取用户详情
export function fetchGetUser(userId: Api.SystemManage.User['userId']) {
  return request<Api.SystemManage.User>({
    url: `/system/user/${userId}`,
    method: 'get'
  });
}
// 新增用户
export function fetchAddUser(data: Api.SystemManage.User) {
  return request({
    url: '/system/user',
    method: 'post',
    data
  });
}
// 修改用户
export function fetchEditUser(data: Api.SystemManage.User) {
  return request({
    url: '/system/user',
    method: 'put',
    data
  });
}
// 删除用户
export function fetchDeleteUser(userIds: Api.SystemManage.User['userId'][]) {
  return request({
    url: `/system/user/${userIds}`,
    method: 'delete'
  });
}

// 用户密码重置
export function resetUserPwd(userId: Api.SystemManage.User['userId'], password: Api.SystemManage.User['password']) {
  return request({
    url: '/system/user/resetPwd',
    method: 'put',
    data: {
      userId,
      password
    }
  });
}

// 用户状态修改
export function changeUserStatus(userId: Api.SystemManage.User['userId'], status: Api.SystemManage.User['status']) {
  return request({
    url: '/system/user/changeStatus',
    method: 'put',
    data: {
      userId,
      status
    }
  });
}

// 查询授权角色
export function getAuthRole(userId: Api.SystemManage.User['userId']) {
  return request({
    url: `/system/user/authRole/${userId}`,
    method: 'get'
  });
}

// 保存授权角色
export function updateAuthRole(userId: Api.SystemManage.User['userId'], roleIds: string) {
  return request({
    url: '/system/user/authRole',
    method: 'put',
    params: {
      userId,
      roleIds
    }
  });
}

// 查询部门下拉树结构
export function fetchGetDeptTree() {
  return request<Api.SystemManage.Dept[]>({
    url: '/system/user/deptTree',
    method: 'get'
  });
}

// 查询岗位和角色列表
export function fetchGetPostAndRoleList() {
  return request<{ posts: Api.SystemManage.Post[]; roles: Api.SystemManage.Role[] }>({
    url: '/system/user/',
    method: 'get'
  });
}

// 同步组织架构
export function reqSyncUser() {
  return request({
    url: '/system/user/syncUser',
    method: 'post',
    timeout: 300000
  });
}
