import request from '@/utils/request';
import { encrypt } from '@/utils/encrypt';
import { loginRSA } from '@/config';

export async function login(data) {
  if (loginRSA) {
    data.password = await encrypt(data.passwords);
  }
  delete data.passwords;
  return request({
    url: '/system/login',
    method: 'post',
    data,
  });
}

export function getUserInfos() {
  return request({
    url: '/system/getUserInfo',
    method: 'get',
  });
}

export function logout() {
  return request({
    url: '/system/logout',
    method: 'post',
  });
}

export function getAuthMenu() {
  return request({
    url: '/sysMenu/select',
    method: 'get',
  });
}
//获取二维码url
export function getQrCode() {
  return request({
    url: '/system/wechat/getQrCode',
    method: 'get',
  });
}
//为用户分配项目
export function assignProject(data) {
  return request({
    url: '/sysUser/assignProject',
    method: 'post',
    data,
  });
}
//查询用户的项目列表
export function getProjectsByUserId(data) {
  return request({
    url: '/sysUser/getProjectsByUserId?userId=' + data.userId,
    method: 'get',
  });
}
// 扫码登录
export function codeLoginCallback(data) {
  return request({
    url: '/system/wechat/login?scene=' + data.scene,
    method: 'get',
  });
}
// 微信和用户绑定
export function userBindWechat(data) {
  return request({
    url: '/system/bind?userName=' + data.userName + '&openid=' + data.openid,
    method: 'post',
  });
}

// 修改密码
export function userUpdatePwd(data) {
  return request({
    url:
      '/sysProfile/updatePwd?oldPwd=' + data.oldPwd + '&newPwd=' + data.newPwd,
    method: 'post',
  });
}

// 修改用户信息
export function updateInfo(data) {
  return request({
    url: '/sysProfile/updateInfo',
    method: 'post',
    data,
  });
}

// 查询用户信息
export function userInfo(data) {
  return request({
    url: '/sysProfile/userInfo',
    method: 'get',
    data,
  });
}
