/**
 * 认证 API
 */
import http from '@/utils/http'
import type { LoginRequest, LoginResponse, UserInfo } from '@/types/api'

/** 登录 */
export async function login(data: LoginRequest): Promise<LoginResponse> {
  const res = await http.post<LoginResponse>('/login', data)
  return res.data
}

/** 登出 */
export async function logout(): Promise<{ success: boolean }> {
  const res = await http.post<{ success: boolean }>('/logout')
  return res.data
}

/** 获取当前用户信息 */
export async function getUserInfo(): Promise<{ success: boolean; user: UserInfo }> {
  const res = await http.get<{ success: boolean; user: UserInfo }>('/api/user/info')
  return res.data
}