import type { UserInfo } from '@vben/types';

import { requestClient } from '#/api/request';

/**
 * 获取用户信息
 */
export async function getUserInfoApi(params: {getRoles?: boolean, getMenus?: boolean}) {
  //修改不要使用json，使用formdata格式发送请求：'/auth/user/query/current'
  const formData = new FormData();
  formData.append('getRoles', params.getRoles?.toString() || 'false');
  formData.append('getMenus', params.getMenus?.toString() || 'false');
  return requestClient.request<UserInfo>('/auth/user/query/current', {
    method: 'POST',
    data: formData,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',

    },
  });
}

async function queryPage(param) {
  return requestClient.post('/auth/user/queryPage', param);
}

async function queryList(param) {
  return requestClient.post('/auth/user/queryList', param);
}
async function create(param) {
  return requestClient.post('/auth/user/create', param);
}

//createYunying
async function createYunying(param) {
  return requestClient.post('/auth/user/createYunying', param);
}



async function assignOrRemoveRole(param){
  return requestClient.post('/auth/user/assignOrRemoveRole', param)
}

async function removeByUid(param) {
  return requestClient.post('/auth/user/removeByUid/' + param.uid, param);
}

async function updateByUid(param) {
  return requestClient.post('/auth/user/update/' + param.uid, param);
}

export const user = {
  queryPage,
  queryList,
  create,
  assignOrRemoveRole,
  removeByUid,
  updateByUid,
  createYunying,
}
