import request from '@/utils/request'
import { praseStrEmpty } from "@/utils/ruoyi";

// 查询用户列表
export function listUser(query) {
  return request({
    url: '/erp/user/list',
    method: 'get',
    params: query
  })
}

export function allUser() {
  return request({
    url: '/erp/user/all',
    method: 'get'
  })
}

// 查询用户详细
export function getUser(userId) {
  return request({
    url: '/erp/user/' + praseStrEmpty(userId),
    method: 'get'
  })
}

// 新增用户
export function addUser(data) {
  return request({
    url: '/erp/user',
    method: 'post',
    data: data
  })
}

// 修改用户
export function updateUser(userId, data) {
  return request({
    url: '/erp/user/' + userId,
    method: 'put',
    data: data
  })
}

// 删除用户
export function delUser(userId) {
  return request({
    url: '/erp/user/' + userId,
    method: 'delete'
  })
}

// 用户密码重置
export function resetUserPwd(userId, newPassword) {
  return request({
    url: '/erp/user/resetPassword/' + userId + '/' + encodeURIComponent(newPassword),
    method: 'put'
  })
}

// 用户状态修改
export function changeUserStatus(userId, enabled) {
  return request({
    url: '/erp/user/modifyEnabled/' + userId + '/' + enabled,
    method: 'put'
  })
}

// 修改用户个人信息
export function updateUserProfile(data) {
  return request({
    url: '/erp/user/profile',
    method: 'put',
    data: data
  })
}

// 用户密码重置
export function updateUserPwd(oldPassword, newPassword) {
  const data = {
    oldPassword,
    password: newPassword
  }
  return request({
    url: '/erp/user/profile/modifyPassword',
    method: 'put',
    data
  })
}


// 获取钉钉所有人员信息
export function getAllDingdingUserApi(data) {
  return request({
    url: '/erp/dingTalkUser/all',
    method: 'get',
    params:data
  })
}

// 关联钉钉和系统用户
export function syncUsersApi(userId, data) {
  return request({
    url: '/erp/user/configDingTalkUser/' + userId,
    method: 'PUT',
    data: data
  })
}

// 将钉钉人员信息全部同步到我们的库中
export function syncUserInfoAPi() {
  return request({
    url: '/erp/dingTalkUser/syncAll',
    method: 'PUT'
  })
}