import request from '@/utils/request';

//获取所有用户信息
export function getAllUsers(params) {
  return request({
    url: '/backend/getAllUsers',
    method: 'get',
    params,
  });
}

//获取租户用户
export function getTenantUsers(tenantId) {
  return request({
    url: `/backend/getTenantUsers/${tenantId}`,
    method: 'get',
  });
}
 
// 获取用户信息
export function getUserInfo(userId) {
  return request({
    url: `/backend/getUserInfo/${userId}`,
    method: 'get',
  });
}

// 添加用户
export function addUser(data) {
  return request({
    url: '/backend/addUser',
    method: 'post',
    data,
  });
}
 
// 编辑用户信息
export function editUser(userId, data) {
  return request({
    url: `/backend/editUser/${userId}`,
    method: 'post',
    data,
  });
}

// 更新用户信息（编辑用户的别名）
export function updateUserInfo(userId, data) {
  return editUser(userId, data);
}

// 更新个人资料
export function updateUserProfile(userId, data) {
  return editUser(userId, data);
}

// 绑定/更换手机号
export function bindPhone(userId, phone) {
  return editUser(userId, { phone });
}

// 绑定/更换邮箱
export function bindEmail(userId, email) {
  return editUser(userId, { email });
}

// 删除用户
export function deleteUser(userId) {
  return request({
    url: `/backend/deleteUser/${userId}`,
    method: 'delete',
  });
}

// 修改密码
export function changePassword(userId, data) {
  return request({
    url: '/backend/changePassword',
    method: 'post',
    data: {
      id: userId,
      password: data.newPassword
    },
  });
}
