import { NestFactory } from '@nestjs/core';
import { ValidationPipe } from '@nestjs/common';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { TelemetryModule } from './telemetry.module';

async function bootstrap() {
  const app = await NestFactory.create(TelemetryModule);
  app.setGlobalPrefix('api/v1');
  app.useGlobalPipes(new ValidationPipe({ whitelist: true, transform: true }));
  app.enableCors();

  const config = new DocumentBuilder()
    .setTitle('Genex Telemetry Service')
    .setDescription('User presence detection, event collection, DAU analytics')
    .setVersion('1.0.0')
    .addBearerAuth()
    .addTag('telemetry', 'Event collection & heartbeat')
    .addTag('admin-telemetry', 'Admin analytics dashboard')
    .build();
  SwaggerModule.setup('docs', app, SwaggerModule.createDocument(app, config));

  await app.listen(parseInt(process.env.PORT || '3011', 10));
}
bootstrap();
