// utils/api-helper.js - API 响应解析

export function isApiSuccess(body) {
  if (!body) return false;
  const code = Number(body.code);
  return code === 200 || code === 0;
}

export function getApiMsg(body) {
  if (!body) return '';
  return body.msg || body.message || '';
}

export function extractUserData(body) {
  if (!body) return {};
  if (body.data && typeof body.data === 'object' && !Array.isArray(body.data)) {
    return body.data;
  }
  const userData = { ...body };
  delete userData.code;
  delete userData.msg;
  delete userData.message;
  return userData;
}

/** 解析扫码场景参数 */
export function parseSceneOptions(options) {
  if (!options || !options.scene) return options || {};
  try {
    const scene = decodeURIComponent(options.scene);
    return { ...options, inviteCode: scene };
  } catch (e) {
    return options;
  }
}

/** 订单状态中文映射 */
const ORDER_STATUS_MAP = {
  1: '已下单', 2: '进行中', 3: '已完成',
  4: '退款中', 5: '已退款', 6: '退款失败',
  7: '指定中', 8: '结算中',
};

export function getOrderStatusText(status) {
  return ORDER_STATUS_MAP[status] || '未知状态';
}
