import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import {ValidationPipe} from "@nestjs/common";
import {DocumentBuilder, SwaggerModule} from "@nestjs/swagger";

// const { createBullBoard } = require('@bull-board/api');
// const { BullAdapter } = require('@bull-board/api/bullAdapter');
// const { BullMQAdapter } = require('@bull-board/api/bullMQAdapter');
// const { ExpressAdapter } = require('@bull-board/express');


async function bootstrap() {
  const app = await NestFactory.create(AppModule, {
    snapshot: true,
  });

  // Global validation pipe
  app.useGlobalPipes(
      new ValidationPipe({
        transform: true,
        whitelist: true,
        forbidNonWhitelisted: true,
      }),
  );

  // CORS
  app.enableCors();

  // Swagger
  const config = new DocumentBuilder()
      .setTitle('🔥 Trend Hunter API')
      .setDescription(
          'API tìm kiếm và tổng hợp trends từ nhiều nguồn social media',
      )
      .setVersion('1.0')
      .addTag('Trends')
      .build();
  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('docs', app, document);

  const port = process.env.PORT || 3000;
  await app.listen(port);

  console.log(`
  🔥 X-News is running!
  📡 API:     http://localhost:${port}
  📖 Swagger: http://localhost:${port}/docs
  `);
}
bootstrap();
