import { api, createApiUrl } from '~/utils/axios';
import type { BaseRespone } from '~/utils/axios';

/**
 * 验证码
 */
export const getCaptcha = createApiUrl('login/getCaptcha');
/**
 * 验证token是否正常
 */
type OvalidateToken = BaseRespone & {
  data: {
    exp_time: string
  }
}
export function validateToken(): Promise<OvalidateToken> {
  return api.post('login/validateToken', {});
}
/**
 * 账号密码登录
 */
export type IaccountLogin = {}
type OaccountLogin = BaseRespone & {
  data: {
    token: string
    exp_time: string
  }
}
export function accountLogin(data: IaccountLogin): Promise<OaccountLogin> {
  return api.post('login/accountLogin', data, {
    isTransformResponse: true,
    isShowErrorMessage: true,
    ignoreLogin: true
  });
}
/**
 * 用户登出
 */
export function userLogout(): Promise<BaseRespone> {
  return api.post(
    'login/userLogout',
    {},
    {
      isTransformResponse: true,
      isShowErrorMessage: true
    }
  );
}
