import { BindCardInfo, LoginInfo, LoginRequestDTO, MobileLoginResponseDTO, RegisterInfo, UserInfo } from "@/types/user";
import { ApiResponse } from "@/types";
import flyio from "../flyio";


/**
 * 手机号登录
 * @param params 手机号登录参数
 * @returns 登录信息
 */
export function login(params: LoginRequestDTO) {
  return flyio.post('/front/user/userLogin', params) as Promise<ApiResponse<MobileLoginResponseDTO>>;
}

/**
 * 用户注册
 * @param params 注册参数
 * @returns 注册结果
 */
export function registry(params: BindCardInfo) {
  return flyio.post('/registry', params) as Promise<ApiResponse<any>>;
}

/**
 * 完善信息
 * @param params 注册参数
 * @returns 注册结果
 */
export function improve(params: BindCardInfo) {
  return flyio.post('/improve', params) as Promise<ApiResponse<any>>;
}

/**
 * 完善信息
 * @param params 注册参数
 * @returns 注册结果
 */
export function improveWithToken(params: BindCardInfo, token: string) {
  return flyio.post('/improve', params, {
    headers: {
      'TempToken': `Bearer ${token}`
    }
  }) as Promise<ApiResponse<any>>;
}

/**
 * 获取用户信息
 * @returns 用户信息
 */
export function getUserInfo() {
  return flyio.get('/front/user/getInfo') as Promise<ApiResponse<UserInfo>>;
}

/**
 * 获取用户信息
 * @returns 用户信息
 */
export function getUserInfoWithToken(token: string) {
  return flyio.get('/front/user/getInfo', {}, {
    headers: {
      'TempToken': `Bearer ${token}`
    }
  }) as Promise<ApiResponse<UserInfo>>;
}


/**
 * 更新用户信息
 * @returns 用户信息
 */
export function updateUserInfo(params: UserInfo) {
  return flyio.put('/front/user/userInfo', params) as Promise<ApiResponse<UserInfo>>;
}

/**
 * 永久注销账号
 * @returns 
 */
export function logoutPhysical() {
  return flyio.post('/logoutPhysical') as Promise<ApiResponse<any>>;
}