import request from '../utils/request';

/**
 * 创建支付链接（易收米）
 * @param {number} orderId - 订单ID
 */
export const createPayment = async (orderId) => {
  try {
    const response = await request.post(`/payment/create/${orderId}`);
    return {
      success: true,
      data: response
    };
  } catch (error) {
    return {
      success: false,
      message: error.message
    };
  }
};

/**
 * 查询订单支付状态
 * @param {string} orderNumber - 订单号
 */
export const queryPaymentStatus = async (orderNumber) => {
  try {
    const response = await request.get(`/payment/query/${orderNumber}`);
    return {
      success: true,
      data: response
    };
  } catch (error) {
    return {
      success: false,
      message: error.message
    };
  }
};

/**
 * 取消订单
 * @param {number} orderId - 订单ID
 */
export const cancelOrder = async (orderId) => {
  try {
    const response = await request.post(`/payment/cancel/${orderId}`);
    return {
      success: true,
      data: response
    };
  } catch (error) {
    return {
      success: false,
      message: error.message
    };
  }
};
