import { request } from '../request'

/**
 * Login
 *
 * @param userName User name
 * @param password Password
 */
export function fetchLogin(account: string, pwd: string) {
  return request<Api.Auth.LoginToken>({
    url: '/admin/v1/user/login',
    method: 'post',
    data: {
      account,
      pwd,
    },
  })
}

/** Get user info */
export function fetchGetUserInfo(userId: number) {
  return request<Api.Auth.UserInfo>({ url: `admin/v1/manager/detail/${userId}` })
}

/**
 * Refresh token
 *
 * @param refreshToken Refresh token
 */
export function fetchRefreshToken(refreshToken: string) {
  return request<Api.Auth.LoginToken>({
    url: '/auth/refreshToken',
    method: 'post',
    data: {
      refreshToken,
    },
  })
}

/**
 * return custom backend error
 *
 * @param code error code
 * @param msg error message
 */
export function fetchCustomBackendError(code: string, msg: string) {
  return request({ url: '/auth/error', params: { code, msg } })
}
