"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
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());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.NestiaEditorComposer = void 0;
const migrate_1 = require("@nestia/migrate");
const prettierEsTreePlugin = __importStar(require("prettier/plugins/estree"));
const prettierTsPlugin = __importStar(require("prettier/plugins/typescript"));
const standalone_1 = require("prettier/standalone");
var NestiaEditorComposer;
(function (NestiaEditorComposer) {
    NestiaEditorComposer.nest = (props) => compose({
        openFile: "README.md,test/start.ts",
        startScript: ["build:test,test", ""],
        migrate: (app) => app.nest(props),
    })(props);
    NestiaEditorComposer.sdk = (props) => __awaiter(this, void 0, void 0, function* () {
        console.log("NestiaEditorComposer.sdk()", props);
        return compose({
            openFile: "README.md,test/start.ts",
            startScript: ["swagger", "hello"],
            migrate: (app) => app.sdk(props),
        })(props);
    });
    const compose = (config) => (props) => __awaiter(this, void 0, void 0, function* () {
        if (props.files !== undefined)
            return {
                success: true,
                data: {
                    files: props.files,
                    openFile: config.openFile,
                    startScript: config.startScript,
                },
            };
        const result = yield migrate_1.NestiaMigrateApplication.validate(props.document);
        if (result.success === false)
            return result;
        const app = result.data;
        const files = config.migrate(app);
        for (const [key, value] of Object.entries(files))
            if (key.substring(key.length - 3) === ".ts")
                try {
                    files[key] = yield (0, standalone_1.format)(value, {
                        parser: "typescript",
                        plugins: [prettierEsTreePlugin, prettierTsPlugin],
                    });
                }
                catch (exp) {
                    console.log(exp);
                }
        return {
            success: true,
            data: {
                files,
                openFile: config.openFile,
                startScript: config.startScript,
            },
        };
    });
})(NestiaEditorComposer || (exports.NestiaEditorComposer = NestiaEditorComposer = {}));
//# sourceMappingURL=NestiaEditorComposer.js.map