"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateAuthV2EntityId = exports.generateGenericEntityId = exports.MIN_COMPLIANT_LENGTH = void 0;
const humanhash_1 = __importDefault(require("humanhash"));
const chemicalFormulaHash_1 = require("./chemicalFormulaHash");
const uuid_1 = require("./uuid");
const hh = new humanhash_1.default();
exports.MIN_COMPLIANT_LENGTH = 16;
const base32Uuid = () => {
    const uuid = (0, uuid_1.uuid)();
    const cleanUuid = uuid.replace(/-/g, '');
    const bigIntUuid = BigInt(`0x${cleanUuid}`);
    const base32 = bigIntUuid.toString(32);
    return base32;
};
const generateGenericEntityId = (prefix, length = 16) => {
    const enforcedLength = length < exports.MIN_COMPLIANT_LENGTH ? exports.MIN_COMPLIANT_LENGTH : length;
    const id = base32Uuid();
    const shortUuid = id.substring(0, enforcedLength);
    const [firstWord, secondWord] = hh.humanize(id).split(/-+/);
    const shortFirstWord = firstWord.substring(0, 5);
    const shortSecondWord = secondWord.substring(0, 5);
    return `${prefix}-${shortFirstWord}-${shortSecondWord}-${shortUuid}`;
};
exports.generateGenericEntityId = generateGenericEntityId;
const generateAuthV2EntityId = (prefix) => {
    return (0, chemicalFormulaHash_1.chemicalFormulaHash)(prefix);
};
exports.generateAuthV2EntityId = generateAuthV2EntityId;
//# sourceMappingURL=entity-ids.js.map