import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import cookieParser from 'cookie-parser';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { ConsoleLogger, ValidationPipe } from '@nestjs/common';
import { json } from 'express';

async function bootstrap() {

  const app = await NestFactory.create(
    AppModule,
    {
      logger: new ConsoleLogger(
        {
          prefix: "[weare]",
          logLevels: ['debug', 'error', 'fatal', 'log', 'verbose', 'warn'],
          json: true
        }
      )
    }
  );

  app.useGlobalPipes(
    new ValidationPipe({
      whitelist: true,
      transform: true,
    })
  );

  // Open API
  const config = new DocumentBuilder().setTitle('weare').setDescription('weare internal api').setVersion('1.0').build();
  const documentFactory = () => SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('api', app, documentFactory);

  // Cookies
  app.use(cookieParser());

  // Payload size
  app.use( json( {limit: "10mb"} ));

  await app.listen(process.env.PORT ?? 3000);
}
bootstrap();
