"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.decrementSequenceId = exports.maxSequenceId = exports.minSequenceId = exports.equalSequenceIds = exports.sequenceIdComparator = void 0;
const index_js_1 = require("../util/index.js");
const sequenceIdComparator = (a, b) => a.sequenceNumber !== b.sequenceNumber
    ? a.sequenceNumber - b.sequenceNumber
    : (a.indexInBatch ?? 0) - (b.indexInBatch ?? 0);
exports.sequenceIdComparator = sequenceIdComparator;
const equalSequenceIds = (a, b) => (0, exports.sequenceIdComparator)(a, b) === 0;
exports.equalSequenceIds = equalSequenceIds;
const minSequenceId = (a, b) => (0, exports.sequenceIdComparator)(a, b) < 0 ? a : b;
exports.minSequenceId = minSequenceId;
const maxSequenceId = (a, b) => (0, exports.sequenceIdComparator)(a, b) > 0 ? a : b;
exports.maxSequenceId = maxSequenceId;
const decrementSequenceId = (sequenceId) => {
    return sequenceId.indexInBatch !== undefined
        ? {
            sequenceNumber: (0, index_js_1.brand)(sequenceId.sequenceNumber),
            indexInBatch: sequenceId.indexInBatch - 1,
        }
        : { sequenceNumber: (0, index_js_1.brand)(sequenceId.sequenceNumber - 1) };
};
exports.decrementSequenceId = decrementSequenceId;
//# sourceMappingURL=sequenceIdUtils.js.map