"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MockerFixed = void 0;
const faker = require("faker");
const random_number_1 = require("./random-number");
class MockerFixed {
    mock(fieldType, fieldName, { length = undefined, maxLength = undefined, minLength = undefined, scapeQuotes = false, checkFieldNameMeaning = false, totalDigits = undefined, decimalDigits = undefined, } = {}) {
        // according to the meaning of the field use a faker function to obtain the mock
        if (checkFieldNameMeaning) {
            const mockByFieldNameMeaning = this.mockByFieldNameMeaning(fieldName);
            if (mockByFieldNameMeaning)
                return mockByFieldNameMeaning;
        }
        switch (fieldType) {
            case 'id':
            case 'datatype.uuid':
                if (!length)
                    length = 1;
                if (length !== 36)
                    return '*'.repeat(length);
                return faker.datatype.uuid();
            case 'boolean':
                return faker.datatype.boolean();
            case 'relationship':
                return '[]';
            case 'json':
                return scapeQuotes ? '{ "foo" : "bar" }'.replace(/"/gi, '\\"') : '{ "foo" : "bar" }';
            case 'json.array':
                return scapeQuotes ? '["foo", "bar"]'.replace(/"/gi, '\\"') : '["foo", "bar"]';
            case 'json.dataLang':
                // add spanish language
                return scapeQuotes ? '["4470b5ab-9d57-4c9d-a68f-5bf8e32f543a"]'.replace(/"/gi, '\\"') : '["4470b5ab-9d57-4c9d-a68f-5bf8e32f543a"]';
            case 'text':
                return faker.lorem.paragraph();
            case 'char':
                if (!length)
                    length = 1;
                return '*'.repeat(length);
            case 'varchar':
            case 'password':
            case 'random.alphaNumeric':
                if (!maxLength)
                    maxLength = 1;
                return '*'.repeat(maxLength);
            case 'tinyint':
            case 'tinyint.unsigned':
                if (!maxLength)
                    maxLength = 2;
                return Number.parseInt('1'.repeat(maxLength));
            case 'int':
            case 'int.unsigned':
                if (!maxLength)
                    maxLength = 6;
                return Number.parseInt('1'.repeat(maxLength));
            case 'bigint':
            case 'bigint.unsigned':
                if (!maxLength)
                    maxLength = 20;
                return Number.parseInt('1'.repeat(maxLength));
            case 'smallint':
            case 'smallint.unsigned':
                if (!maxLength)
                    maxLength = 4;
                return Number.parseInt('1'.repeat(maxLength));
            case 'decimal':
                return totalDigits && decimalDigits ? Number.parseFloat('1'.repeat(totalDigits) + '.' + '1'.repeat(decimalDigits)) : Number.parseFloat('1'.repeat(5) + '.' + '1'.repeat(2));
            case 'random.float':
                return maxLength ? (0, random_number_1.default)(maxLength) : faker.datatype.float();
            case 'timestamp':
            case 'timestamp.recent':
                return '2022-01-01 00:00:00';
            case 'date':
                return '2022-01-01';
            default:
                throw new Error(`
                    Command Faker ${fieldType} not recognized, check FakeJs API:
                    https://github.com/marak/Faker.js/
                `);
            /* case 'database.column':
                if (params.length > 0 && typeof params[0] === 'number') return faker.random.alphaNumeric(params[0]);
                return faker.database.column();

            case 'lorem.paragraph':
                if (params.length > 0 && typeof params[0] === 'number') return faker.random.alphaNumeric(params[0]);
                return faker.lorem.paragraph();

            case 'random.number.length':
                return Math.floor(+(1 + '0'.repeat(params[0] as number - 1) )) + Math.random() * +(9 + '0'.repeat(params[0] as number- 1)));
            */
        }
    }
    mockByFieldNameMeaning(fieldName) {
        switch (fieldName) {
            case 'image':
                return faker.image.image();
            case 'name':
                return faker.commerce.productName();
            case 'slug':
                return faker.lorem.slug();
        }
    }
}
exports.MockerFixed = MockerFixed;
