import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ValidationPipe } from '@nestjs/common';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { NestExpressApplication } from '@nestjs/platform-express';
import { join } from 'path';

async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);
  
  // Enable CORS
  app.enableCors();
  
  // Enable validation
  app.useGlobalPipes(new ValidationPipe());

  // Serve static files from the public directory
  app.useStaticAssets(join(process.cwd(), 'public'));

  // Swagger setup
  const config = new DocumentBuilder()
    .setTitle('Barcode Generator API')
    .setDescription('API for generating barcodes with structured label numbers')
    .setVersion('1.0')
    .addTag('barcodes')
    .build();
  
  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('api', app, document);

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