"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.idAllocatorFromState = exports.idAllocatorFromMaxId = exports.ChangesetLocalIdSchema = exports.CrossFieldTarget = void 0;
const common_utils_1 = require("@fluidframework/common-utils");
const util_1 = require("../../util");
/**
 * @alpha
 */
var CrossFieldTarget;
(function (CrossFieldTarget) {
    CrossFieldTarget[CrossFieldTarget["Source"] = 0] = "Source";
    CrossFieldTarget[CrossFieldTarget["Destination"] = 1] = "Destination";
})(CrossFieldTarget = exports.CrossFieldTarget || (exports.CrossFieldTarget = {}));
exports.ChangesetLocalIdSchema = (0, util_1.brandedNumberType)();
/**
 * @alpha
 */
function idAllocatorFromMaxId(maxId = undefined) {
    return idAllocatorFromState({ maxId: maxId !== null && maxId !== void 0 ? maxId : (0, util_1.brand)(-1) });
}
exports.idAllocatorFromMaxId = idAllocatorFromMaxId;
function idAllocatorFromState(state) {
    return (c) => {
        const count = c !== null && c !== void 0 ? c : 1;
        (0, common_utils_1.assert)(count > 0, 0x5cf /* Must allocate at least one ID */);
        const id = (0, util_1.brand)(state.maxId + 1);
        state.maxId = (0, util_1.brand)(state.maxId + count);
        return id;
    };
}
exports.idAllocatorFromState = idAllocatorFromState;
//# sourceMappingURL=crossFieldQueries.js.map