"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PrimitiveTransformer = void 0;
const typescript_1 = require("typescript");
const runtime_1 = require("@tsoa/runtime");
const transformer_1 = require("./transformer");
class PrimitiveTransformer extends transformer_1.Transformer {
    static resolveKindToPrimitive(syntaxKind) {
        switch (syntaxKind) {
            case typescript_1.SyntaxKind.NumberKeyword:
                return 'number';
            case typescript_1.SyntaxKind.StringKeyword:
                return 'string';
            case typescript_1.SyntaxKind.BooleanKeyword:
                return 'boolean';
            case typescript_1.SyntaxKind.VoidKeyword:
                return 'void';
            case typescript_1.SyntaxKind.UndefinedKeyword:
                return 'undefined';
            case typescript_1.SyntaxKind.NullKeyword:
                return 'null';
            default:
                return undefined;
        }
    }
    transform(defaultNumberType, typeNode, partentJsDocTagNames) {
        const resolvedType = PrimitiveTransformer.resolveKindToPrimitive(typeNode.kind);
        if (!resolvedType) {
            return;
        }
        switch (resolvedType) {
            case 'number':
                return this.transformNumber(defaultNumberType, partentJsDocTagNames);
            case 'string':
            case 'boolean':
            case 'void':
            case 'undefined':
                return { dataType: resolvedType };
            case 'null':
                return {
                    dataType: 'enum',
                    enums: [null],
                };
            default:
                return (0, runtime_1.assertNever)(resolvedType);
        }
    }
    transformNumber(defaultNumberType, partentJsDocTagNames) {
        if (!partentJsDocTagNames || partentJsDocTagNames.length === 0) {
            return { dataType: defaultNumberType };
        }
        const tags = partentJsDocTagNames.filter(name => {
            return ['isInt', 'isLong', 'isFloat', 'isDouble'].some(m => m === name);
        });
        switch (tags[0]) {
            case 'isInt':
                return { dataType: 'integer' };
            case 'isLong':
                return { dataType: 'long' };
            case 'isFloat':
                return { dataType: 'float' };
            case 'isDouble':
                return { dataType: 'double' };
            default:
                return { dataType: defaultNumberType };
        }
    }
}
exports.PrimitiveTransformer = PrimitiveTransformer;
//# sourceMappingURL=primitiveTransformer.js.map