"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AutoBeTypeScriptCompiler = void 0;
const transform_1 = __importDefault(require("@nestia/core/lib/transform"));
const embed_typescript_1 = require("embed-typescript");
const typescript_1 = __importDefault(require("typescript"));
const transform_2 = __importDefault(require("typia/lib/transform"));
const external_json_1 = __importDefault(require("./raw/external.json"));
class AutoBeTypeScriptCompiler {
    compile(props) {
        return __awaiter(this, void 0, void 0, function* () {
            var _a, _b;
            const alias = (_a = props.package) !== null && _a !== void 0 ? _a : "@ORGANIZATION/PROJECT-api";
            const compiler = new embed_typescript_1.EmbedTypeScript({
                external: external_json_1.default,
                compilerOptions: {
                    target: typescript_1.default.ScriptTarget.ESNext,
                    module: typescript_1.default.ModuleKind.CommonJS,
                    downlevelIteration: true,
                    paths: {
                        [alias]: ["./src/api"],
                        [`${alias}/lib/`]: ["./src/api"],
                        [`${alias}/lib/*`]: ["./src/api/*"],
                    },
                    strict: true,
                    skipLibCheck: true,
                    esModuleInterop: true,
                    experimentalDecorators: true,
                    emitDecoratorMetadata: true,
                },
                transformers: (program, diagnostics) => ({
                    before: [
                        (0, transform_2.default)(program, {}, {
                            addDiagnostic: (input) => diagnostics.push(input),
                        }),
                        (0, transform_1.default)(program, {}, {
                            addDiagnostic: (input) => diagnostics.push(input),
                        }),
                    ],
                }),
            });
            return compiler.compile(Object.assign(Object.assign({}, props.files), ((_b = props.prisma) !== null && _b !== void 0 ? _b : {})));
        });
    }
}
exports.AutoBeTypeScriptCompiler = AutoBeTypeScriptCompiler;
//# sourceMappingURL=AutoBeTypeScriptCompiler.js.map