"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const _cliter_1 = require("../../../@cliter");
const uuid_1 = require("uuid");
const handlebars = require("handlebars");
const _ = require("lodash");
var MockType;
(function (MockType) {
    MockType["FIXED_UUID"] = "fixedUuid";
    MockType["POSTMAN"] = "postman";
    MockType["SEED"] = "seed";
    MockType["FIXED_DATA"] = "fixedData";
})(MockType || (MockType = {}));
handlebars.registerHelper('mocker', function ({ type = MockType.SEED, property = undefined, uuidSeed = 'aurora', hasUuidSeed = true, // boolean to allow for create the same uuid
scapeQuotes = true, checkFieldNameMeaning = true, length = undefined, maxLength = undefined, minLength = undefined, totalDigits = undefined, decimalDigits = undefined, schema = undefined, } = {}) {
    // namespace to generate same uuid, see https://www.npmjs.com/package/uuid
    const namespace = '01a94203-63ba-4c07-bb92-bb61cd2b8e41';
    // take uuid seed or use aurora word to generate uuid
    if (type === MockType.FIXED_UUID)
        return (0, uuid_1.v5)(uuidSeed, namespace);
    // set spanish uuid language, for langId field in i18n entity
    if ((property === null || property === void 0 ? void 0 : property.type) === _cliter_1.SqlType.ID
        && (length || (property === null || property === void 0 ? void 0 : property.length)) === 36
        && property.isI18n
        && property.name === 'langId')
        return '4470b5ab-9d57-4c9d-a68f-5bf8e32f543a';
    if ((property === null || property === void 0 ? void 0 : property.type) === _cliter_1.SqlType.ID
        && hasUuidSeed
        && (length || (property === null || property === void 0 ? void 0 : property.length)) === 36)
        return (0, uuid_1.v5)(uuidSeed, namespace);
    if ((property === null || property === void 0 ? void 0 : property.type) === _cliter_1.SqlType.ENUM && type === MockType.SEED)
        return property.enumOptions ? `${schema === null || schema === void 0 ? void 0 : schema.boundedContextName.toPascalCase()}${schema === null || schema === void 0 ? void 0 : schema.moduleName.toPascalCase()}${property.name.toPascalCase()}.${_.shuffle(property.enumOptions)[0]}` : null;
    if ((property === null || property === void 0 ? void 0 : property.type) === _cliter_1.SqlType.ENUM)
        return property.enumOptions ? `'${_.shuffle(property.enumOptions)[0]}'` : null;
    if ((property === null || property === void 0 ? void 0 : property.type) === _cliter_1.SqlType.RELATIONSHIP)
        return '[]';
    let propertyTotalDigits = 5;
    let propertyDecimalDigits = 3;
    if (property && Array.isArray(property.decimals)) {
        propertyTotalDigits = property.decimals[0];
        propertyDecimalDigits = property.decimals[1];
    }
    if (type === MockType.FIXED_DATA)
        return new _cliter_1.MockerFixed().mock((property === null || property === void 0 ? void 0 : property.faker) ? property.faker : property === null || property === void 0 ? void 0 : property.type, property === null || property === void 0 ? void 0 : property.name, {
            scapeQuotes,
            checkFieldNameMeaning,
            length: length || (property === null || property === void 0 ? void 0 : property.length),
            maxLength: maxLength || ((property === null || property === void 0 ? void 0 : property.maxLength) && property.maxLength > 1 ? property.maxLength - 1 : property && property.maxLength),
            minLength: minLength || (property === null || property === void 0 ? void 0 : property.minLength),
            totalDigits: totalDigits || propertyTotalDigits,
            decimalDigits: decimalDigits || propertyDecimalDigits,
        });
    return new _cliter_1.Mocker().mock((property === null || property === void 0 ? void 0 : property.faker) ? property.faker : property === null || property === void 0 ? void 0 : property.type, property === null || property === void 0 ? void 0 : property.name, {
        scapeQuotes,
        checkFieldNameMeaning,
        length: length || (property === null || property === void 0 ? void 0 : property.length),
        maxLength: maxLength || ((property === null || property === void 0 ? void 0 : property.maxLength) && property.maxLength > 1 ? property.maxLength - 1 : property && property.maxLength),
        minLength: minLength || (property === null || property === void 0 ? void 0 : property.minLength),
        totalDigits: totalDigits || propertyTotalDigits,
        decimalDigits: decimalDigits || propertyDecimalDigits,
    });
});
