/*
 * @Author: Gui
 * @Date: 2023-03-01 19:20:44
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2024-01-03 14:17:14
 * @Description: kxs files
 * @filePath:
 */
import { http } from "@/utils/http";
import { baseUrlApi } from "./utils";
import encryptByDES from "@/utils/encryptByDES";

export type UserResult = {
  status: String;
  data: {
    SysAdminId: string;
    realName: string;
    rightList: any;
    apiToken: string;
    /** 用户名 */
    username: string;
    /** 当前登陆用户的角色 */
    roles: Array<string>;
    /** `token` */
    accessToken: string;
    /** 用于调用刷新`accessToken`的接口时所需的`token` */
    refreshToken: string;
    /** `accessToken`的过期时间（格式'xxxx/xx/xx xx:xx:xx'） */
    expires: Date;
  };
};

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

/** 登录 */
export const getLogin = (data?: object) => {
  console.log(data)
  return http.post("/login", data);
  // return http.get(baseUrlApi("/api/v1/sysadmin/login"), data);
};

/** 刷新token */
export const refreshTokenApi = (data?: object) => {
  return http.request<RefreshTokenResult>(
    "post", "/refreshtoken",
    { data: { value: encryptByDES(JSON.stringify(data)) } }
  );
};
