import { get, post } from '../utils/request';
import type { CouponItem, PaginatedResult } from './coupon';

export interface HoldingsSummary {
  count: number;
  totalFaceValue: number;
  totalSaved: number;
}

/** 获取我的持仓 */
export function getMyHoldings(params?: { status?: string; page?: number; limit?: number }) {
  return get<PaginatedResult<CouponItem>>('/api/v1/coupons/my', {
    status: params?.status,
    page: params?.page ?? 1,
    limit: params?.limit ?? 20,
  });
}

/** 获取持仓汇总 */
export function getHoldingsSummary() {
  return get<HoldingsSummary>('/api/v1/coupons/my/summary');
}

/** 核销券（出示二维码后由商户扫码，此处为用户侧调用） */
export function redeemCoupon(couponId: string) {
  return post<{ redemptionId: string }>('/api/v1/redemptions/scan', { couponId });
}
