"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Installer = void 0;
const typescript_1 = require("typescript");
const cliter_config_1 = require("../../config/cliter.config");
const drivers_1 = require("./drivers");
exports.Installer = {
    declareBackPackageModule(sourceFile, boundedContextName, items) {
        if (drivers_1.ImportDriver.hasImportDeclarations(sourceFile, `${boundedContextName.toPascalCase()}Module`))
            return;
        drivers_1.ImportDriver.createImportItems(sourceFile, `${cliter_config_1.cliterConfig.apiContainer}/${boundedContextName.toKebabCase()}/${boundedContextName.toKebabCase()}.module`, items);
        const classDecoratorArguments = drivers_1.DecoratorDriver.getClassDecoratorArguments(sourceFile, 'AppModule', 'Module');
        const importsArray = drivers_1.ObjectDriver.getInitializerProperty(classDecoratorArguments, 'imports');
        importsArray.addElement(`${boundedContextName.toPascalCase()}Module`, { useNewLines: true });
    },
    declareFrontNavigationMenu(sourceFile, boundedContextName, navigationItem) {
        drivers_1.ImportDriver.createImportItems(sourceFile, `./apps/${boundedContextName.toKebabCase()}/${boundedContextName.toKebabCase()}.navigation`, [`${boundedContextName.toCamelCase()}Navigation`]);
        drivers_1.ArrayDriver.addArrayItem(sourceFile, navigationItem, 'adminNavigation');
    },
    declareFrontRouting(sourceFile, boundedContextName, index = 5) {
        const appRoutesArray = drivers_1.VariableDriver.getInitializerVariable(sourceFile, 'appRoutes');
        const objectRoute = appRoutesArray.getElements()[index];
        const childrenRoutesArray = drivers_1.ObjectDriver.getInitializerProperty(objectRoute, 'children');
        const childrenRoutesElements = childrenRoutesArray.getElements();
        // avoid duplicated declaration
        for (const element of childrenRoutesElements) {
            const pathProperty = element.getPropertyOrThrow('path');
            const pathString = pathProperty.getInitializerIfKindOrThrow(typescript_1.SyntaxKind.StringLiteral);
            if (pathString.getText() === `'${boundedContextName.toKebabCase()}'`)
                return;
        }
        // set routes
        childrenRoutesArray === null || childrenRoutesArray === void 0 ? void 0 : childrenRoutesArray.addElement(`{ path: '${boundedContextName.toKebabCase()}', loadChildren: () => import('app/modules/admin/apps/${boundedContextName.toKebabCase()}/${boundedContextName.toKebabCase()}.module').then(m => m.${boundedContextName.toPascalCase()}Module) },`, { useNewLines: true });
    },
    changeModuleDecoratorPropertyAdapter(sourceFile, moduleName, decoratorName, propertyName, provide, adapter, adapterPath) {
        if (drivers_1.ImportDriver.hasImportDeclarations(sourceFile, adapter))
            return;
        drivers_1.ImportDriver.createImportItems(sourceFile, adapterPath, [adapter]);
        drivers_1.DecoratorDriver.changeModuleDecoratorPropertyAdapter(sourceFile, moduleName, decoratorName, propertyName, provide, adapter);
    },
};
