import { get, post } from "@/common/http/request";

export interface LoginParams {
  username: string;
  password: string;
  verifyCode?: string;
}

export interface Token {
  accessToken: string;
  refreshToken: string;
}

export const UserService = {
  // 登录
  login(params: LoginParams) {
    const loginParams = new URLSearchParams();
    loginParams.append("username", params.username);
    loginParams.append("password", params.password);
    return post("/auth/login", loginParams);
  },

  checkIsLogined() {
    return get("/open/check-login");
  },

  /**
   * 检测登录状态
   * 用于前端页面刷新后检测当前token是否有效
   */
  checkLogin() {
    return get("/open/check-login");
  },

  // 获取用户信息
  getUserInfo() {
    return get("/auth/getUserInfo");
  },

  getDynamicRouter() {
    return get("/auth/getRouterConfigRawList");
  },

  logout() {
    return post("/auth/logout");
  },
};
