"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.applyVersion = applyVersion;
exports.checkForStaleVersion = checkForStaleVersion;
const util_1 = require("../util");
const merge_objects_1 = require("../objects/merge-objects");
const getVersion_1 = require("./getVersion");
const getIncludeListFromItemType_1 = require("./_internal/getIncludeListFromItemType");
/**
 * Applies the versioned data to the model
 * @param model
 * @param version
 * @param includeList
 * @returns
 */
function applyVersion(model, version, includeList) {
    if (!includeList) {
        includeList = (0, getIncludeListFromItemType_1.getIncludeListFromItemType)(model);
    }
    return (0, merge_objects_1.mergeObjects)(version.data, (0, util_1.cloneObject)(model), includeList);
}
/**
 * Checks if the upstream version is newer than the passed in version
 * @param itemId
 * @param version
 * @param requestOptions
 * @returns
 */
async function checkForStaleVersion(itemId, version, requestOptions) {
    const upstream = await (0, getVersion_1.getVersion)(itemId, version.id, requestOptions);
    const isStale = upstream.updated > version.updated;
    return {
        isStale,
        updated: upstream.updated,
    };
}
//# sourceMappingURL=utils.js.map