"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.fakeIdAllocator = exports.idAllocatorFromState = exports.idAllocatorFromMaxId = void 0;
const internal_1 = require("@fluidframework/core-utils/internal");
const utils_js_1 = require("./utils.js");
/**
 * @internal
 */
function idAllocatorFromMaxId(maxId = undefined) {
    return idAllocatorFromState({ maxId: maxId ?? -1 });
}
exports.idAllocatorFromMaxId = idAllocatorFromMaxId;
function idAllocatorFromState(state) {
    return {
        allocate: (c) => {
            const count = c ?? 1;
            (0, internal_1.assert)(count > 0, 0x5cf /* Must allocate at least one ID */);
            const id = state.maxId + 1;
            state.maxId += count;
            return id;
        },
        getMaxId: () => state.maxId,
    };
}
exports.idAllocatorFromState = idAllocatorFromState;
exports.fakeIdAllocator = {
    allocate: () => (0, utils_js_1.fail)("Should not allocate IDs"),
    getMaxId: () => 0,
};
//# sourceMappingURL=idAllocator.js.map