import { http } from '@/utils/http/axios';
import { UserProps } from './user-operate';
import { OrganizationUserTree } from '@/views/system/user/types';
export interface BasicResponseModel<T = any> {
  code: number;
  message: string;
  data: T;
}

export interface BasicPageParams {
  pageNumber: number;
  pageSize: number;
  total: number;
}

/**
 * @description: 获取用户信息
 */
export function getUserInfo(params: { tenantCode?: string }) {
  return http.request(
    {
      url: '/login/info',
      method: 'POST',
      params,
    },
    {
      isShowErrorMessage: false,
    },
  );
}

/**
 * @description: 添加/编辑用户
 */
export function addUsur(params) {
  return http.request({
    url: '/user/add',
    method: 'POST',
    params,
  });
}

/**
 * @description: 编辑用户
 */
export function editUsur(params) {
  return http.request({
    url: '/user/update',
    method: 'POST',
    params,
  });
}

/**
 * @description: 用户信息
 */
export function userInfo(params: UserProps) {
  return http.request({
    url: '/admin/user/queryUserInfo',
    method: 'GET',
    params,
  });
}

/**
 * @description: 删除用户
 */
export function delUser(params) {
  return http.request({
    url: '/user/delete',
    method: 'POST',
    params,
  });
}

interface LoginParams {
  username: string;
  password: string;
}

/**
 * @description: 用户登录
 */
export function login(params: LoginParams) {
  return http.request<BasicResponseModel>(
    {
      url: '/login/auth',
      method: 'POST',
      params,
    },
    {
      isTransformResponse: false,
    },
  );
}

/**
 * @description: 用户修改密码
 */
export function changePassword(params) {
  return http.request({
    url: '/login/updatePwd',
    method: 'POST',
    params,
  });
}

/**
 * @description: 修改用户信息
 */
export function editUserInfo(params) {
  return http.request({
    url: '/login/updateUser',
    method: 'POST',
    params,
  });
}

/**
 * @description: 用户登出
 */
export function logout(params) {
  return http.request({
    url: '/user/doLogout',
    method: 'POST',
    params,
  });
}

/**
 * @description: 获取用户列表
 */
export function getUserList(params) {
  return http.request({
    url: '/user/list',
    method: 'GET',
    params,
  });
}

/**
 * @description: 获取在线用户列表
 */
export function onlineList(params) {
  return http.request({
    url: '/online/userList',
    method: 'GET',
    params,
  });
}

/**
 * @description: 在线用户强制退出
 */
export function onlineLogOut(params?) {
  return http.request({
    url: '/online/logOut',
    method: 'GET',
    params,
  });
}

/**
 * @description: V4: 根据工号模糊查询组织人员树
 */
export function queryOrganizationUserTree(workNo: number) {
  return http.request<OrganizationUserTree[]>({
    url: '/admin/hrdatasync/queryOrganizationUserTreeDataByWorkNo',
    method: 'POST',
    data: { workNo },
  });
}
