"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AutoBeTestRandomProgrammer = void 0;
const typescript_1 = __importDefault(require("typescript"));
const ExpressionFactory_1 = require("typia/lib/factories/ExpressionFactory");
const writeTestExpression_1 = require("./writeTestExpression");
var AutoBeTestRandomProgrammer;
(function (AutoBeTestRandomProgrammer) {
    AutoBeTestRandomProgrammer.pickRandom = (ctx, expr) => typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createPropertyAccessExpression(typescript_1.default.factory.createIdentifier(ctx.importer.external({
        type: "instance",
        library: "@nestia/e2e",
        name: "RandomGenerator",
    })), "pick"), undefined, [(0, writeTestExpression_1.writeTestExpression)(ctx, expr.array)]);
    AutoBeTestRandomProgrammer.sampleRandom = (ctx, expr) => ExpressionFactory_1.ExpressionFactory.currying({
        function: typescript_1.default.factory.createPropertyAccessExpression(typescript_1.default.factory.createIdentifier(ctx.importer.external({
            type: "instance",
            library: "@nestia/e2e",
            name: "RandomGenerator",
        })), "sample"),
        arguments: [
            (0, writeTestExpression_1.writeTestExpression)(ctx, expr.array),
            (0, writeTestExpression_1.writeTestExpression)(ctx, expr.count),
        ],
    });
    AutoBeTestRandomProgrammer.booleanRandom = (_ctx, expr) => {
        var _a;
        return typescript_1.default.factory.createLessThanEquals(typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createPropertyAccessExpression(typescript_1.default.factory.createIdentifier("Math"), "random"), undefined, undefined), typescript_1.default.factory.createNumericLiteral((_a = expr.probability) !== null && _a !== void 0 ? _a : 0.5));
    };
    AutoBeTestRandomProgrammer.integerRandom = (ctx, expr) => {
        const intersection = [
            typescript_1.default.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.NumberKeyword),
            createTypiaTag(ctx, "Type", [
                typescript_1.default.factory.createLiteralTypeNode(typescript_1.default.factory.createStringLiteral("int32")),
            ]),
        ];
        if (expr.minimum !== null && expr.minimum !== undefined)
            intersection.push(createTypiaTag(ctx, "Minimum", [
                typescript_1.default.factory.createLiteralTypeNode(typescript_1.default.factory.createNumericLiteral(expr.minimum)),
            ]));
        if (expr.maximum !== null && expr.maximum !== undefined)
            intersection.push(createTypiaTag(ctx, "Maximum", [
                typescript_1.default.factory.createLiteralTypeNode(typescript_1.default.factory.createNumericLiteral(expr.maximum)),
            ]));
        if (expr.multipleOf !== null && expr.multipleOf !== undefined)
            intersection.push(createTypiaTag(ctx, "MultipleOf", [
                typescript_1.default.factory.createLiteralTypeNode(typescript_1.default.factory.createNumericLiteral(expr.multipleOf)),
            ]));
        return createTypiaRandom(ctx, intersection);
    };
    AutoBeTestRandomProgrammer.numberRandom = (ctx, expr) => {
        const intersection = [
            typescript_1.default.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.NumberKeyword),
        ];
        if (expr.minimum !== null && expr.minimum !== undefined)
            intersection.push(createTypiaTag(ctx, "Minimum", [
                typescript_1.default.factory.createLiteralTypeNode(typescript_1.default.factory.createNumericLiteral(expr.minimum)),
            ]));
        if (expr.maximum !== null && expr.maximum !== undefined)
            intersection.push(createTypiaTag(ctx, "Maximum", [
                typescript_1.default.factory.createLiteralTypeNode(typescript_1.default.factory.createNumericLiteral(expr.maximum)),
            ]));
        if (expr.multipleOf !== null && expr.multipleOf !== undefined)
            intersection.push(createTypiaTag(ctx, "MultipleOf", [
                typescript_1.default.factory.createLiteralTypeNode(typescript_1.default.factory.createNumericLiteral(expr.multipleOf)),
            ]));
        return createTypiaRandom(ctx, intersection);
    };
    AutoBeTestRandomProgrammer.stringRandom = (ctx, expr) => {
        const intersection = [
            typescript_1.default.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.StringKeyword),
        ];
        if (expr.minLength !== null && expr.minLength !== undefined)
            intersection.push(createTypiaTag(ctx, "MinLength", [
                typescript_1.default.factory.createLiteralTypeNode(typescript_1.default.factory.createNumericLiteral(expr.minLength)),
            ]));
        if (expr.maxLength !== null && expr.maxLength !== undefined)
            intersection.push(createTypiaTag(ctx, "MaxLength", [
                typescript_1.default.factory.createLiteralTypeNode(typescript_1.default.factory.createNumericLiteral(expr.maxLength)),
            ]));
        return createTypiaRandom(ctx, intersection);
    };
    AutoBeTestRandomProgrammer.formatRandom = (ctx, expr) => typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createPropertyAccessExpression(typescript_1.default.factory.createIdentifier(ctx.importer.external({
        type: "default",
        library: "typia",
        name: "typia",
    })), "random"), [
        typescript_1.default.factory.createIntersectionTypeNode([
            typescript_1.default.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.StringKeyword),
            typescript_1.default.factory.createTypeReferenceNode(typescript_1.default.factory.createQualifiedName(typescript_1.default.factory.createIdentifier(ctx.importer.external({
                type: "instance",
                library: "typia",
                name: "tags",
            })), typescript_1.default.factory.createIdentifier("Format")), [
                typescript_1.default.factory.createLiteralTypeNode(typescript_1.default.factory.createStringLiteral(expr.format)),
            ]),
        ]),
    ], []);
    AutoBeTestRandomProgrammer.patternRandom = (ctx, expr) => typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createPropertyAccessExpression(typescript_1.default.factory.createIdentifier(ctx.importer.external({
        type: "default",
        library: "typia",
        name: "typia",
    })), "random"), [
        typescript_1.default.factory.createIntersectionTypeNode([
            typescript_1.default.factory.createKeywordTypeNode(typescript_1.default.SyntaxKind.StringKeyword),
            typescript_1.default.factory.createTypeReferenceNode(typescript_1.default.factory.createQualifiedName(typescript_1.default.factory.createIdentifier(ctx.importer.external({
                type: "instance",
                library: "typia",
                name: "tags",
            })), typescript_1.default.factory.createIdentifier("Pattern")), [
                typescript_1.default.factory.createLiteralTypeNode(typescript_1.default.factory.createStringLiteral(expr.pattern)),
            ]),
        ]),
    ], []);
    AutoBeTestRandomProgrammer.keywordRandom = (ctx, expr) => {
        let value = typescript_1.default.factory.createPropertyAccessExpression(typescript_1.default.factory.createIdentifier(ctx.importer.external({
            type: "instance",
            library: "@nestia/e2e",
            name: "RandomGenerator",
        })), expr.keyword);
        new Array(KEYWORD_CURRYING_COUNT[expr.keyword]).fill(0).forEach(() => {
            value = typescript_1.default.factory.createCallExpression(value, undefined, undefined);
        });
        return value;
    };
})(AutoBeTestRandomProgrammer || (exports.AutoBeTestRandomProgrammer = AutoBeTestRandomProgrammer = {}));
const createTypiaTag = (ctx, name, typeArguments) => typescript_1.default.factory.createTypeReferenceNode(typescript_1.default.factory.createQualifiedName(typescript_1.default.factory.createIdentifier(ctx.importer.external({
    type: "instance",
    library: "typia",
    name: "tags",
})), typescript_1.default.factory.createIdentifier(name)), typeArguments);
const createTypiaRandom = (ctx, typeArguments = []) => typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createPropertyAccessExpression(typescript_1.default.factory.createIdentifier(ctx.importer.external({
    type: "default",
    library: "typia",
    name: "typia",
})), "random"), typeArguments.length === 0
    ? undefined
    : typeArguments.length === 1
        ? typeArguments
        : [typescript_1.default.factory.createIntersectionTypeNode(typeArguments)], undefined);
const KEYWORD_CURRYING_COUNT = {
    alphabets: 1,
    alphaNumeric: 1,
    mobile: 1,
    name: 1,
    paragraph: 2,
    content: 3,
};
//# sourceMappingURL=AutoBeTestRandomProgrammer.js.map