"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AssetWhereResponseMerger = void 0;
const tslib_1 = require("tslib");
const inversify_1 = require("inversify");
const _ = require("lodash");
/** IMPORTANT!!!  Merges two `ListResult<CabinetAssetVersion>` instances (NOT raw `CabinetAssetVersion` entities).
 */
let AssetWhereResponseMerger = class AssetWhereResponseMerger {
    constructor() {
    }
    merge(original, additional) {
        // Extract the entity from the response envelope
        let originalOut = original === null || original === void 0 ? void 0 : original.output;
        let additionalOut = additional === null || additional === void 0 ? void 0 : additional.output;
        // Merge the entities into 1
        let ult = this.mergeEntities(originalOut !== null && originalOut !== void 0 ? originalOut : [], additionalOut);
        // rewrite the original output
        original.output = ult;
        return original;
    }
    /** Mutates the original */
    mergeEntities(original, additional) {
        var _a;
        try {
            if (additional == undefined || _.isEmpty(additional))
                return original;
            original.push(...additional);
            return original;
        }
        catch (err) {
            const errMsg = "Error merging CabinetAssetVersion instances: ".concat((_a = err.message) !== null && _a !== void 0 ? _a : "");
            throw new Error(errMsg);
        }
    }
};
AssetWhereResponseMerger = tslib_1.__decorate([
    (0, inversify_1.injectable)(),
    tslib_1.__metadata("design:paramtypes", [])
], AssetWhereResponseMerger);
exports.AssetWhereResponseMerger = AssetWhereResponseMerger;
//# sourceMappingURL=asset-where-entity-merger.js.map