"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.compositeValues = exports.createByGenerator = exports.createByType = void 0;
const uuid_1 = require("uuid");
const humanhash_1 = __importDefault(require("humanhash"));
const hh = new humanhash_1.default();
const entityIdPrefixByTypeName = {
    AssetAccount: 'aa',
    Payment: 'pa',
    Policy: 'pol',
    PolicyControl: 'poc',
    PolicyRule: 'por',
};
const createIsoDatetime = (name, typeName) => new Date().toISOString();
const createIsoDate = (name, typeName) => new Date().toISOString().split('T').shift();
const createEntityId = (name, typeName) => {
    const id = uuid_1.v4();
    const prefix = entityIdPrefixByTypeName[typeName] || 'noprefix';
    const shortUuid = id.split('-').join('').substring(0, 12);
    const humanized = hh.humanize(id).split('---').join('-').split('--').join('-');
    return `${prefix}-${humanized}-${shortUuid}`;
};
const createVersion = () => {
    const now = new Date();
    const startOfDfns = new Date('2021-01-01');
    const msSince2021 = now.valueOf() - startOfDfns.valueOf();
    const secondsSince2021 = Math.floor(msSince2021 / 1000);
    return secondsSince2021.toString(32);
};
const scalarFactories = {
    IsoDatetime: createIsoDatetime,
    IsoDate: createIsoDate,
    EntityId: createEntityId,
};
const generatorFactories = {
    Verion: createIsoDatetime,
};
const createByType = (factoryName, name, typeName) => {
    const factory = scalarFactories[factoryName];
    if (typeof factory === 'function') {
        return factory(name, typeName);
    }
    else {
        throw new Error(`createByType: unable to generate item for factory: ${factoryName}, name: ${name}, typeName: ${typeName}`);
    }
};
exports.createByType = createByType;
const createByGenerator = (generatorName, name, typeName) => {
    const factory = generatorFactories[generatorName];
    if (typeof factory === 'function') {
        return factory(name, typeName);
    }
    else {
        throw new Error(`createByGenerator: unable to generate item for generatorName: ${generatorName}, name: ${name}, typeName: ${typeName}`);
    }
};
exports.createByGenerator = createByGenerator;
const compositeValues = (...values) => values.join('_');
exports.compositeValues = compositeValues;
