import { NestFactory } from '@nestjs/core';
import { RidersModule } from './riders.module';
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
import { ValidationPipe } from '@nestjs/common';

async function bootstrap() {
  // Create the main HTTP server
  const app = await NestFactory.create(RidersModule);

  // Add global pipes if needed (optional)
  app.useGlobalPipes(new ValidationPipe());

  // Create and attach the microservice (TCP in your case)
  app.connectMicroservice<MicroserviceOptions>({
    transport: Transport.TCP,
    options: {
      host: '0.0.0.0',
      port: 8879,
    },
  });

  // Start all microservices (including the TCP)
  await app.startAllMicroservices();

  // Start HTTP server to listen on port 3000 (or any port you want)
  await app.listen(3000);
}

bootstrap();
