"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.accumulateFees = accumulateFees;
exports.feeMapToArray = feeMapToArray;
exports.sortFees = sortFees;
exports.mapSimpleFeesToItemisedFees = mapSimpleFeesToItemisedFees;
/**
 * Helper function to accumulate given fees into the given feeMap.
 */
function accumulateFees(feeMap, fees, quantity = 1, nightsModifier = 1) {
    fees.forEach((itemisedFee) => {
        const currentAmount = feeMap.get(itemisedFee.hotelFee) || 0;
        feeMap.set(itemisedFee.hotelFee, currentAmount + itemisedFee.amount * quantity * nightsModifier);
    });
}
/**
 * Converts an accumulated Map of fees into an array of ItemisedFee objects.
 */
function feeMapToArray(feeMap) {
    return Array.from(feeMap.entries()).map(([hotelFee, amount]) => ({
        hotelFee,
        amount,
    }));
}
/**
 * Sorts an array of ItemisedFee objects based on their position in hotelFees array.
 */
function sortFees(fees, hotelFees) {
    return [...fees].sort((a, b) => {
        const indexA = hotelFees.findIndex((f) => f.name === a.hotelFee.name);
        const indexB = hotelFees.findIndex((f) => f.name === b.hotelFee.name);
        return indexA - indexB;
    });
}
function mapSimpleFeesToItemisedFees(fees, hotelFees) {
    return fees
        .map((fee) => {
        const hotelFee = hotelFees.find((f) => f.name === fee.name);
        if (!hotelFee) {
            return null;
        }
        return {
            hotelFee,
            amount: fee.amount,
        };
    })
        .filter((fee) => fee !== null);
}
//# sourceMappingURL=Fee.js.map