import { request } from "@/utils/http";

export type UserResult = {
  success: boolean;
  code: number;
  message: string;
  data: {
    token: string;

    userinfo: {
      account: string;
      is_super: boolean;
      permission: string[];
      id: number;
      nickname: string;
    };
  };
};

export type RefreshTokenResult = {
  success: boolean;
  data: {
    /** `token` */
    accessToken: string;
    /** 用于调用刷新`accessToken`的接口时所需的`token` */
    refreshToken: string;
    /** `accessToken`的过期时间（格式'xxxx/xx/xx xx:xx:xx'） */
    expires: Date;
  };
};

/** 登录 */
export const getLogin = (data?: object) => {
  // return request.request<UserResult>("post", "/api/auth", { data });
  return request.request<UserResult>("post", "/archivesService/agency/login", {
    data
  });
};

/** 刷新token */
export const refreshTokenApi = (data?: object) => {
  return request.request<RefreshTokenResult>("post", "/refreshToken", { data });
};
