import { get, post } from '@/lib/request'
import type { SystemUser } from '../system'

export interface CaptchaRes { captchaImg: string; captchaId: string }
export interface LoginParams { account: string; password: string; captcha: string; captchaId: string }
export interface LoginResponse { token: string; userInfo: SystemUser }

const BASE_URL = '/auth'

export async function getCaptcha() {
  return get<CaptchaRes>(`${BASE_URL}/captcha`)
}

export async function login(data: LoginParams) {
  return post<LoginResponse>(`${BASE_URL}/login`, data)
}

export async function getUserInfo() {
  return get<SystemUser>(`${BASE_URL}/info`)
}

export async function updateProfile(data: Partial<Pick<SystemUser, 'name' | 'nickName' | 'phone' | 'avatarId'>>) {
  return post<null>(`${BASE_URL}/update`, data)
}

export async function logout() {
  // 后端无 logout 接口，仅清理本地状态
  return Promise.resolve()
}
