"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateApiModule = generateApiModule;
function hasApiModuleRegistration(module) {
    return module.apiModuleRegistration !== undefined;
}
function generateApiModule({ backend: { modules } }) {
    const imports = [];
    const moduleImports = [];
    const moduleProviders = [];
    for (const module of modules) {
        if (hasApiModuleRegistration(module) && module.apiModuleRegistration.import) {
            imports.push(module.apiModuleRegistration.import);
        }
        if (module.moduleClass) {
            imports.push(`import { ${module.moduleClass.name} } from '${module.moduleClass.location}'`);
        }
        if (hasApiModuleRegistration(module) && module.apiModuleRegistration.code) {
            moduleImports.push(module.apiModuleRegistration.code);
        }
        else if (module.moduleClass) {
            moduleImports.push(module.moduleClass.name);
        }
        if (module.apiModuleRegistration?.provider) {
            for (const provider of module.apiModuleRegistration.provider) {
                moduleProviders.push(provider);
            }
        }
    }
    return /*ts*/ `
import { DynamicModule } from '@nestjs/common'

${imports.join('\n')}

import type { ApiConfig } from './api.config'
import { ApiController } from './api.controller'

export class ApiModule {
  public static forRoot({ config }: { config: ApiConfig }): DynamicModule {
    return {
      module: ApiModule,

      imports: [
        ${moduleImports.join(',\n')}
      ],
      controllers: [ApiController],
      providers: [${moduleProviders.join(', ')}],
    }
  }
}
  `;
}
//# sourceMappingURL=api-module.generator.js.map