"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateActionsModule = generateActionsModule;
const generator_1 = require("@postxl/generator");
function generateActionsModule({ actions, database }) {
    const imports = generator_1.ImportGenerator
        //
        .from(actions.module.location)
        .add(actions.execution.class)
        .add(actions.dispatcher)
        .add(actions.authorization.service)
        .add(actions.config)
        .addType(actions.config.options)
        .add(database.module.moduleClass); // NOSONAR
    const moduleImports = [];
    for (const { module: { moduleClass }, } of actions.providers) {
        if (!moduleClass) {
            continue;
        }
        imports.add(moduleClass);
        moduleImports.push(`forwardRef(() => ${moduleClass.name})`);
    }
    return /* ts */ `
import { DynamicModule, forwardRef, Provider } from '@nestjs/common'

${imports.generate()}

export class ${actions.module.name} {
  public static forRoot(options: ${actions.config.options.name}): DynamicModule {
    const configProvider: Provider = {
      provide: ${actions.config.name},
      useValue: new ${actions.config.name}(options)
    }
    return {
      module: ${actions.module.name},
      imports: [
        ${database.module.moduleClass.name},
        ${moduleImports.join(',\n')}
      ],
      providers: [${actions.dispatcher.name}, ${actions.execution.class.name}, ${actions.authorization.service.name}, configProvider],
      exports: [${actions.dispatcher.name}, ${actions.execution.class.name}, ${actions.authorization.service.name}],
      global: true
    }
  }
}`;
}
//# sourceMappingURL=actions-module.generator.js.map