import { defHttp } from '/@/utils/http/axios'
import {
  LoginParams,
  // LoginResultModel,
  GetUserInfoByUserIdParams,
  GetUserInfoByUserIdModel,
  GetUserInfoModel
} from './model/userModel'

import { ErrorMessageMode } from '/@/utils/http/axios/types'

enum Api {
  Login = '/backstage/login',
  Logout = '/backstage/login/out',
  GetUserInfo = '/backstage/manager/currentuser',
  GetPermCodeByUserId = '/getPermCodeByUserId',
  GetToken = '/login/project/name',
  GetAccountGroupList = '/backstage/account/group'
}

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

/**
 * @description: getUserInfoById
 */
export function getUserInfo() {
  return defHttp.get<GetUserInfoModel>({
    url: Api.GetUserInfo
  })
}

export function getPermCodeByUserId(params: GetUserInfoByUserIdParams) {
  return defHttp.get<string[]>({
    url: Api.GetPermCodeByUserId,
    params
  })
}

export function getXsrfToken(code: string) {
  return defHttp.get({
    url: Api.GetToken,
    params: { code }
  })
}

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

/** 获取账号组 */
export function getAccountGroupList() {
  return defHttp.get({
    url: Api.GetAccountGroupList
  })
}
