import { cloneObject } from "../util";
import { mergeObjects } from "../objects/merge-objects";
import { getVersion } from "./getVersion";
import { getIncludeListFromItemType } from "./_internal/getIncludeListFromItemType";
/**
 * Applies the versioned data to the model
 * @param model
 * @param version
 * @param includeList
 * @returns
 */
export function applyVersion(model, version, includeList) {
    if (!includeList) {
        includeList = getIncludeListFromItemType(model);
    }
    return mergeObjects(version.data, cloneObject(model), includeList);
}
/**
 * Checks if the upstream version is newer than the passed in version
 * @param itemId
 * @param version
 * @param requestOptions
 * @returns
 */
export async function checkForStaleVersion(itemId, version, requestOptions) {
    const upstream = await getVersion(itemId, version.id, requestOptions);
    const isStale = upstream.updated > version.updated;
    return {
        isStale,
        updated: upstream.updated,
    };
}
//# sourceMappingURL=utils.js.map