"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.syncBasketAddonRowQuantities = syncBasketAddonRowQuantities;
const core_1 = require("@roomstay/core");
/**
 * Synchronizes addon row quantities based on basket row occupancy.
 * Handles per-person, per-adult, per-child, and per-all-persons pricing types.
 *
 * @param addonRow - The addon row to potentially update
 * @param basketRow - The basket row containing occupancy data
 * @returns true if any field was changed, false otherwise
 */
function syncBasketAddonRowQuantities(addonRow, basketRow) {
    const addon = addonRow.getAddon();
    if (!addon)
        return false;
    const type = addon.pricingType;
    const isPerPersonType = [core_1.EAddonPricingType.PER_PERSON, core_1.EAddonPricingType.PER_PERSON_PER_NIGHT].includes(type);
    const syncAdults = [
        core_1.EAddonPricingType.PER_PERSON,
        core_1.EAddonPricingType.PER_PERSON_PER_NIGHT,
        core_1.EAddonPricingType.PER_ADULT_OCCUPANCY_PER_NIGHT,
        core_1.EAddonPricingType.PER_ALL_PERSONS,
        core_1.EAddonPricingType.PER_ALL_PERSONS_PER_NIGHT,
    ].includes(type);
    const syncChildren = [core_1.EAddonPricingType.PER_CHILD_OCCUPANCY_PER_NIGHT, core_1.EAddonPricingType.PER_ALL_PERSONS, core_1.EAddonPricingType.PER_ALL_PERSONS_PER_NIGHT].includes(type);
    if (!syncAdults && !syncChildren)
        return false;
    let changed = false;
    if (syncAdults && addonRow.getAdultQuantity() !== basketRow.getAdults()) {
        addonRow.setAdultQuantity(basketRow.getAdults());
        changed = true;
    }
    if (isPerPersonType && addonRow.getQuantity() !== basketRow.getAdults()) {
        addonRow.setQuantity(basketRow.getAdults());
        changed = true;
    }
    if (syncChildren && addonRow.getChildQuantity() !== basketRow.getChildren()) {
        addonRow.setChildQuantity(basketRow.getChildren());
        changed = true;
    }
    return changed;
}
//# sourceMappingURL=SyncBasketAddonRowQuantities.js.map