/**
 * 全局扫码搜索结果格式化（对齐 ticketBooking `formatScanGlobal`）。
 */

/**
 * 将 handleGlobalScan 返回的原始结构格式化为 UI/OS 统一结构。
 *
 * @example
 * ```ts
 * const formatted = formatGlobalScanResult(
 *   { searchType: 'wallet', response: { code: 200, data: { customer: {...} } } },
 *   'WL123',
 * );
 * // => { searchType: 'wallet', data: customerObj, scanCode: 'WL123' }
 * ```
 */
export function formatGlobalScanResult(raw, scanCode) {
  if (!(raw !== null && raw !== void 0 && raw.searchType)) return null;
  var searchType = raw.searchType;
  var _ref = raw.response || {},
    resultData = _ref.data,
    code = _ref.code;
  if (code !== 200 && searchType !== 'local_product') {
    return null;
  }
  if (searchType === 'wallet') {
    return {
      searchType: searchType,
      data: resultData === null || resultData === void 0 ? void 0 : resultData.customer,
      scanCode: scanCode
    };
  }
  if (searchType === 'walletPass') {
    var _resultData$;
    return {
      searchType: searchType,
      data: resultData === null || resultData === void 0 || (_resultData$ = resultData[0]) === null || _resultData$ === void 0 ? void 0 : _resultData$.customer,
      scanCode: scanCode
    };
  }
  if (searchType === 'product' || searchType === 'local_product') {
    return {
      searchType: searchType,
      data: resultData,
      scanCode: scanCode
    };
  }
  if (searchType === 'order') {
    return {
      searchType: searchType,
      data: resultData,
      scanCode: scanCode
    };
  }
  return null;
}