/**
 * This is not a production server yet!
 * This is only a minimal backend to get started.
 */

import { Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';

import { AppModule } from './app/app.module';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { MicroserviceOptions } from '@nestjs/microservices';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  // const globalPrefix = 'api';
  // app.setGlobalPrefix(globalPrefix);

  app.connectMicroservice<MicroserviceOptions>({
    options: { host: '0.0.0.0', port: process.env.MICROSERVICE_PORT },
  });

  await app.startAllMicroservices();
  const config = new DocumentBuilder()
  .setTitle('Rag Service')
  .setDescription('Rag Service API description')
  .setVersion('1.0')
  .addBearerAuth({ type: 'http', name: 'authorization', in: 'header' }, 'authorization')
  .addServer(`https://64c7-122-173-29-192.ngrok-free.app/`, "production server")
  .addServer(`http://localhost:${process.env.PORT}/`, "local server")
  .build();
const document = SwaggerModule.createDocument(app, config);

SwaggerModule.setup('docs', app, document);
  const port = process.env.PORT || 3000;
  await app.listen(port);
  Logger.log(
    `🚀 Application is running on: http://localhost:${port}`
  );
}

bootstrap();
