import { defHttp } from '/@/utils/http/axios';

import { ErrorMessageMode } from '/#/axios';
import { GetUserInfoModel, LoginParams, LoginResultModel } from './model';

enum Api {
  Login = '/system/login', //
  Logout = '/system/logout', //
  GetUserInfo = '/organization/user/current/info', //
}

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

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

//  ------------
export function doLogout() {
  return defHttp.post({ url: Api.Logout });
}
