"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BackHandler = void 0;
/* eslint-disable unicorn/no-static-only-class */
const types_1 = require("../types");
const template_generator_1 = require("../utils/template-generator");
const common_1 = require("../functions/common");
const back_1 = require("../functions/back");
const store_1 = require("../store");
const fs = require("node:fs");
const path = require("node:path");
class BackHandler {
    static async new(newBackCommandState) {
        if (!newBackCommandState.appName)
            throw new Error('To create back application is required app name');
        // create directory for application
        if (!fs.existsSync(newBackCommandState.appName))
            fs.mkdirSync(newBackCommandState.appName, { recursive: true });
        await template_generator_1.TemplateGenerator.generateStaticContents(newBackCommandState.command, types_1.TemplateElement.BACK_APPLICATION, path.join(newBackCommandState.appName), '.', {
            force: newBackCommandState.flags.force,
            verbose: newBackCommandState.flags.verbose,
        });
    }
    static async generateModule(generateCommandState, { hasGenerateTestingFiles = false, } = {}) {
        // generate module files
        await (0, back_1.generateAppFiles)(generateCommandState);
        // generate pivot tables
        await (0, back_1.generatePivotTables)(generateCommandState);
        // generate i18n module files
        await (0, back_1.generateI18nAppFiles)(generateCommandState);
        // generate @api files
        await (0, back_1.generateApiFiles)(generateCommandState);
        // generate additional api filles
        await (0, back_1.generateAdditionalApiFiles)(generateCommandState);
        // generate @api i18n files
        await (0, back_1.generateI18NApiFiles)(generateCommandState);
        // create references, write imports in ts files
        (0, back_1.addReferences)(generateCommandState);
        // flag to generate e2e tests, this test can overwrite custom tests
        if (hasGenerateTestingFiles)
            await (0, back_1.generateTestingFiles)(generateCommandState);
        // generate postman files
        await (0, back_1.generatePostmanFiles)(generateCommandState);
        // create yaml file
        (0, back_1.generateYamlConfigFile)(generateCommandState);
        (0, common_1.generateJsonLockFile)(generateCommandState, store_1.GlobalState.hasValue('lockFiles') ? store_1.GlobalState.getValue('lockFiles') : []);
    }
    static async addPackage(addCommandState) {
        await (0, back_1.addPackageFiles)(addCommandState);
    }
}
exports.BackHandler = BackHandler;
