import type { UserInfo } from '/#/store';
import { defHttp } from '/@/utils/http/axios';
import { LoginParams, LoginResultModel, GetUserInfoModel } from './model/userModel';
import { encodeStr } from '/@/utils/encodeUtil';
import { ErrorMessageMode } from '/#/axios';
import type { AppRouteRecordRaw } from '/@/router/types';

enum Api {
  // Login = '/basic-api/login',
  Login = '/service/agent/fdLogin',
  Logout = '/service/agent/fdLogout',
  GetUserInfo = '/service/agent/getUserInfo',
  GetPermCode = '/service/manage/sysMenu/getButtonByUserId',
}

/**
 * @description: user login api
 */
export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<LoginResultModel>(
    {
      url: Api.Login,
      params:{
        ...params,
        phoneNum:params.username,
        password: encodeStr(window.btoa(params.password))
    },
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * @description: getUserInfo
 */
export function getUserInfo() {
  return defHttp.post<UserInfo>({ url: Api.GetUserInfo }, { errorMessageMode: 'none' });
}

export function getPermCode() {
  return defHttp.get<AppRouteRecordRaw[]>({ url: Api.GetPermCode });
}

export function doLogout() {
  return defHttp.get({ url: Api.Logout });
}
