import request from '@/utils/request';
import type { ApiResult, PageResult } from '@/api';
import type { ShopRechargeRecord, ShopRechargeRecordParam } from './model';

/**
 * 分页查询充值记录
 */
export async function pageRechargeRecord(params: ShopRechargeRecordParam) {
  const res = await request.get<ApiResult<PageResult<ShopRechargeRecord>>>(
    '/shop/recharge-record/page',
    { params }
  );
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 获取充值记录详情
 */
export async function getRechargeRecordById(id: number) {
  const res = await request.get<ApiResult<ShopRechargeRecord>>(
    `/shop/recharge-record/${id}`
  );
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
