import { _objectSpread2 } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { setDefaultCapacitys } from "../../../components/booking/info2/service/addService/utils.js";
import { mergeFormIntoExtend } from "./mergeFormIntoExtend.js";
//#region src/plus/salesSdk/bookingEditService/resolveCacheItemForResourceCheck.ts
/**
* 补齐 _extend.capacity（Info2 getProductExtend → setDefaultCapacitys，默认 [{ value: 1 }]）。
* 与 info2 一致：capacity 仅表示人数/套餐占用，不按 relation_id 扩展。
*/
function ensureDefaultCapacityOnItem(item) {
	var _item$_data$capacitys, _item$_data, _ext$quantity;
	if (!item) return item;
	const ext = item._extend || {};
	if (Array.isArray(ext.capacity) && ext.capacity.length > 0) return item;
	const nextCapacity = setDefaultCapacitys({
		capacitys: (_item$_data$capacitys = (_item$_data = item._data) === null || _item$_data === void 0 ? void 0 : _item$_data.capacitys) !== null && _item$_data$capacitys !== void 0 ? _item$_data$capacitys : item === null || item === void 0 ? void 0 : item.capacity,
		cacheItem: item
	});
	return _objectSpread2(_objectSpread2({}, item), {}, { _extend: _objectSpread2(_objectSpread2({}, ext), {}, {
		capacity: nextCapacity,
		quantity: (_ext$quantity = ext.quantity) !== null && _ext$quantity !== void 0 ? _ext$quantity : 1
	}) });
}
/** 合并表单、补齐默认 capacity（供资源可用性校验 / 加车 booking 使用）。 */
function resolveCacheItemForResourceCheck(item, formValues) {
	if (!item) return item;
	return ensureDefaultCapacityOnItem(_objectSpread2(_objectSpread2({}, item), {}, { _extend: mergeFormIntoExtend(item._extend, formValues || {}) }));
}
//#endregion
export { resolveCacheItemForResourceCheck };
