"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Analytics = void 0;
/**
 * Abstract class used to transform roomstay data into either GA4 or UA analytics events
 *
 * All logging still happens from the {@link DataLayer} class.
 */
class Analytics {
    constructor() {
        this.currency = { original: '', current: '' };
        this.itemListName = '';
        /**
         * Merges the current user's data (user_id) into the provided input object.
         * Ensures the resulting object always includes user_id when available.
         */
        this.withUserData = (input) => {
            return this.withClientDetailsData(Object.assign(Object.assign({}, input), (('ecommerce' in input || input.event === 'login') && Object.assign({}, this.getUserData()))));
        };
        /**
         * Merges the current company name/property name into the provided input object.
         */
        this.withClientDetailsData = (input) => {
            var _a, _b;
            return Object.assign(Object.assign({}, input), { company: (_a = this.company) === null || _a === void 0 ? void 0 : _a.name, property: (_b = this.hotel) === null || _b === void 0 ? void 0 : _b.name });
        };
        /**
         * Get addon row total price from Reservations API response
         */
        this.getAddonRowTotalFromReservations = (addonRow, reservations) => {
            var _a;
            const addonCode = addonRow.getAddon().code;
            const matchedAddon = (_a = reservations.reservations[0].addons) === null || _a === void 0 ? void 0 : _a.find((addon) => addon.code === addonCode);
            return matchedAddon === null || matchedAddon === void 0 ? void 0 : matchedAddon.total;
        };
    }
    initialise(company, hotel) {
        this.company = company;
        this.hotel = hotel;
    }
    setUserId(id) {
        this.userId = id;
    }
    setItemListName(itemListName) {
        this.itemListName = itemListName || '';
    }
    // Returns an object containing the current user_id if available.
    getUserData() {
        return this.userId ? { user_id: this.userId } : {};
    }
    updateCurrency(current, original) {
        this.currency = { current, original };
    }
    generateRefundMessageObjectByReservationNumber(reservationNumber) {
        return {
            event: 'refund',
            ecommerce: {
                refund: {
                    actionField: {
                        id: reservationNumber,
                    },
                },
            },
        };
    }
}
exports.Analytics = Analytics;
//# sourceMappingURL=Analytics.js.map