import { _asyncToGenerator } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
import { request } from "../../../utils/index.js";
//#region src/plus/pisellReservation/serve/productQuery.ts
/**
* POST /product/query — 按 id 拉取商品详情（用于预约规则 link 商品回填）。
*
* 参数对齐参考的 `ProductList.loadProducts`，仅保留在 reservation 页面足够的字段：
* - `product_ids` → 映射到后端字段 `ids`
* - `schedule_date` / `schedule_datetime`
* 其余如 `customer_id`、`front_end_cache_id`、`useCache` 等在本场景下不需要。
*/
/**
* 返回按 `sort` 倒序的商品列表；接口失败或返回异常结构时返回空数组（保持调用点简洁）。
*/
function queryProductsByIds(_x) {
	return _queryProductsByIds.apply(this, arguments);
}
function _queryProductsByIds() {
	_queryProductsByIds = _asyncToGenerator(function* (params) {
		const { product_ids, schedule_date, schedule_datetime } = params;
		if (!Array.isArray(product_ids) || product_ids.length === 0) return [];
		try {
			var _res$data;
			const res = yield request.getRequest().post(`/shop/product/query`, {
				open_quotation: 1,
				open_bundle: 0,
				exclude_extension_type: [
					"product_party",
					"product_event",
					"product_series_event",
					"product_package_ticket",
					"ticket",
					"event_item"
				],
				with: [
					"category",
					"collection",
					"resourceRelation"
				],
				status: "published",
				num: 500,
				skip: 1,
				ids: product_ids,
				schedule_date,
				schedule_datetime,
				application_code: "online-store",
				is_eject: 1,
				open_deposit: 1
			}, {
				fullResult: true,
				isShopApi: true,
				customToast: () => {}
			});
			const body = (_res$data = res === null || res === void 0 ? void 0 : res.data) !== null && _res$data !== void 0 ? _res$data : res;
			const payload = body && typeof body === "object" && "data" in body ? body.data : body;
			const rawList = payload === null || payload === void 0 ? void 0 : payload.list;
			return (Array.isArray(rawList) ? rawList : []).slice().sort((a, b) => Number(b === null || b === void 0 ? void 0 : b.sort) - Number(a === null || a === void 0 ? void 0 : a.sort));
		} catch (error) {
			console.error("[PisellReservation] queryProductsByIds failed", error);
			return [];
		}
	});
	return _queryProductsByIds.apply(this, arguments);
}
//#endregion
export { queryProductsByIds };
