import request from '@/utils/request'
import type { ApiResult } from '@/api'
import type { UserBalance } from './model'

/**
 * 获取当前用户余额信息（跨库读取 gxwebsoft_core.sys_user）
 * 通过 paopao-api 本地 /auth/user-balance 接口，无需跨域请求 core 系统
 */
export async function getUserBalance(): Promise<UserBalance> {
  const res = await request.get<ApiResult<any>>(
    '/auth/user-balance'
  )
  if (res.code === 0 && res.data) {
    const data = res.data
    return {
      balance: data.balance != null ? String(data.balance) : '0',
      frozenBalance: '0',
      totalIncome: '0',
      totalExpense: '0',
    }
  }
  return Promise.reject(new Error(res.message || '获取余额失败'))
}
