import { post } from '../utils/request';

/**
 * 用户相关接口
 */

/**
 * 登录结果接口
 */
export interface LoginResult {
  token: string;
  userInfo: UserInfo;
}

/**
 * 用户信息接口
 */
export interface UserInfo {
  id: number;
  nickname: string;
  phone: string;
  avatar: string;
}

/**
 * 账号密码登录（临时方案）
 */
export const loginByPassword = (params: { phone: string; password: string }): Promise<LoginResult> => {
  return post<LoginResult>('/login/password', params);
};

/**
 * 微信手机号一键登录
 * @param params { code, encryptedData, iv }
 */
export const loginByWechatPhone = (params: { code: string; encryptedData?: string; iv?: string }): Promise<LoginResult> => {
  return post<LoginResult>('/login/wechat-phone', params);
};

/**
 * 获取用户信息
 */
export const getUserInfo = (): Promise<UserInfo> => {
  return post<UserInfo>('/login/user-info');
};

/**
 * 退出登录
 */
export const logout = (): Promise<void> => {
  return post<void>('/login/logout');
};
