import { assert } from "../../../shared/src/asserts.js";
import { parseBigInt } from "../../../shared/src/parse-big-int.js";
export function versionToLexi(v) {
    assert(v >= 0, 'Negative versions are not supported');
    assert(typeof v === 'bigint' ||
        (v <= Number.MAX_SAFE_INTEGER && Number.isInteger(v)), `Invalid or unsafe version ${v}`);
    const base36Version = BigInt(v).toString(36);
    const length = BigInt(base36Version.length - 1).toString(36);
    assert(length.length === 1, `Value is too large to be encoded as a LexiVersion: ${v.toString()}`);
    return `${length}${base36Version}`;
}
export function versionFromLexi(lexiVersion) {
    assert(lexiVersion.length >= 2);
    const length = lexiVersion.substring(0, 1);
    const base36Version = lexiVersion.substring(1);
    assert(base36Version.length === parseInt(length, 36) + 1, `Invalid LexiVersion: ${lexiVersion}`);
    return parseBigInt(base36Version, 36);
}
export function max(...versions) {
    let winner = versions[0];
    for (let i = 1; i < versions.length; i++) {
        const b = versions[i];
        winner = winner > b ? winner : b;
    }
    return winner;
}
export function min(...versions) {
    let winner = versions[0];
    for (let i = 1; i < versions.length; i++) {
        const b = versions[i];
        winner = winner < b ? winner : b;
    }
    return winner;
}
export function oneAfter(version) {
    return versionToLexi(versionFromLexi(version) + 1n);
}
//# sourceMappingURL=lexi-version.js.map