import request from '@/utils/request'
import type { ApiResult } from '@/api'
import type { UserRecharge, RechargeRequest } from './model'

export type { UserRecharge, RechargeRequest }

/**
 * 创建用户充值订单
 * 注意：后端可能需要实现此接口
 */
export async function createUserRecharge(data: RechargeRequest): Promise<UserRecharge> {
  const res = await request.post<ApiResult<UserRecharge>>(
    '/shop/shop-recharge/create',
    data
  )
  if (res.code === 0 && res.data) {
    return res.data
  }
  return Promise.reject(new Error(res.message))
}

/**
 * 发起充值支付
 * 注意：后端可能需要实现此接口
 */
export async function payUserRecharge(rechargeId: number): Promise<any> {
  const res = await request.post<ApiResult<any>>(
    '/shop/shop-recharge/pay',
    { rechargeId }
  )
  if (res.code === 0 && res.data) {
    return res.data
  }
  return Promise.reject(new Error(res.message))
}
