import request from '@/utils/request'

export interface RefundDetail {
  orderNo: string;
  refundMoney: string;
  reason: string;
  status: number;
  statusText: string;
  time: string;
  steps: RefundStep[];
}

export interface RefundStep {
  title: string;
  desc: string;
  time: string;
  done: boolean;
}

/**
 * 获取退款详情
 * @param orderId 订单ID
 * @returns 退款详情
 */
export async function getRefundDetail(orderId: string): Promise<RefundDetail> {
  try {
    const res = await request.get('/order/refund/detail', {
      params: { orderId }
    });
    return res.data;
  } catch (error) {
    console.error('获取退款详情失败', error);
    throw error;
  }
}

/**
 * 取消退款申请
 * @param orderId 订单ID
 * @returns 是否成功
 */
export async function cancelRefund(orderId: string): Promise<boolean> {
  try {
    const res = await request.post('/order/refund/cancel', {
      data: { orderId }
    });
    return res.code === 0;
  } catch (error) {
    console.error('取消退款失败', error);
    throw error;
  }
}
