const require_objectSpread2 = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_syncBundleFromExtendOther = require("./syncBundleFromExtendOther.js");
//#region src/plus/salesSdk/utils/buildProductLineUpdates.ts
/**
* 编辑商品行时构造 updateOrderProduct.updates：
* 保留 v2 metadata 主价，由 OrderModule.normalizeOrderProduct 按新 bundle/option 重算 composite。
*/
function buildProductLineUpdates(orderLine, productPatch) {
	var _patchMeta$source_pro, _patchMeta$main_produ, _patchMeta$main_produ2, _patchMeta$price_over, _patchMeta$origin, _patchMeta$origin$_ex, _patchMeta$origin2, _patchMeta$origin3, _productPatch$product, _productPatch$product2, _productPatch$discoun;
	const patchMeta = productPatch.metadata || {};
	const lineMeta = orderLine.metadata || {};
	const sourceProductPrice = (_patchMeta$source_pro = patchMeta.source_product_price) !== null && _patchMeta$source_pro !== void 0 ? _patchMeta$source_pro : lineMeta.source_product_price;
	const mainProductSellingPrice = (_patchMeta$main_produ = patchMeta.main_product_selling_price) !== null && _patchMeta$main_produ !== void 0 ? _patchMeta$main_produ : lineMeta.main_product_selling_price;
	const mainProductOriginalPrice = (_patchMeta$main_produ2 = patchMeta.main_product_original_price) !== null && _patchMeta$main_produ2 !== void 0 ? _patchMeta$main_produ2 : lineMeta.main_product_original_price;
	const priceOverride = (_patchMeta$price_over = patchMeta.price_override) !== null && _patchMeta$price_over !== void 0 ? _patchMeta$price_over : (_patchMeta$origin = patchMeta.origin) === null || _patchMeta$origin === void 0 || (_patchMeta$origin = _patchMeta$origin._extend) === null || _patchMeta$origin === void 0 ? void 0 : _patchMeta$origin.priceOverride;
	const otherBundle = (_patchMeta$origin$_ex = (_patchMeta$origin2 = patchMeta.origin) === null || _patchMeta$origin2 === void 0 || (_patchMeta$origin2 = _patchMeta$origin2._extend) === null || _patchMeta$origin2 === void 0 || (_patchMeta$origin2 = _patchMeta$origin2.other) === null || _patchMeta$origin2 === void 0 ? void 0 : _patchMeta$origin2.bundle) !== null && _patchMeta$origin$_ex !== void 0 ? _patchMeta$origin$_ex : (_patchMeta$origin3 = patchMeta.origin) === null || _patchMeta$origin3 === void 0 || (_patchMeta$origin3 = _patchMeta$origin3._extend) === null || _patchMeta$origin3 === void 0 || (_patchMeta$origin3 = _patchMeta$origin3.skuValue) === null || _patchMeta$origin3 === void 0 ? void 0 : _patchMeta$origin3.bundle;
	const hasPriceOverride = priceOverride !== void 0 && priceOverride !== null && priceOverride !== "";
	const baseBundle = (_productPatch$product = productPatch.product_bundle) !== null && _productPatch$product !== void 0 ? _productPatch$product : orderLine.product_bundle;
	const productBundle = hasPriceOverride ? require_syncBundleFromExtendOther.syncBundleFromExtendOther(baseBundle, otherBundle) : (_productPatch$product2 = productPatch.product_bundle) !== null && _productPatch$product2 !== void 0 ? _productPatch$product2 : orderLine.product_bundle;
	const updates = {
		num: productPatch.num,
		note: productPatch.note,
		tax_fee: productPatch.tax_fee,
		is_charge_tax: productPatch.is_charge_tax,
		discount_list: (_productPatch$discoun = productPatch.discount_list) !== null && _productPatch$discoun !== void 0 ? _productPatch$discoun : orderLine.discount_list,
		product_option_item: productPatch.product_option_item,
		metadata: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, lineMeta), patchMeta), sourceProductPrice !== void 0 ? { source_product_price: String(sourceProductPrice) } : {}), mainProductSellingPrice !== void 0 ? { main_product_selling_price: String(mainProductSellingPrice) } : {}), mainProductOriginalPrice !== void 0 ? { main_product_original_price: String(mainProductOriginalPrice) } : {}), hasPriceOverride ? { price_override: String(priceOverride) } : {}), hasPriceOverride ? { is_manual_discount: 1 } : {}), {}, { price_schema_version: 2 })
	};
	if (productBundle !== void 0) updates.product_bundle = productBundle;
	return updates;
}
//#endregion
exports.buildProductLineUpdates = buildProductLineUpdates;
