import { NestFactory } from "@nestjs/core";
import { AppModule } from "./app.module";
import { Logger } from "@nestjs/common";

const logger = new Logger("Orchestrator");

async function bootstrap() {
  const app = await NestFactory.create(AppModule, {
    logger: ["error", "warn", "log", "debug", "verbose"],
  });

  const port = process.env.ORCHESTRATOR_PORT ?? 3001;
  const host = process.env.HOST ?? process.env.BIND_ADDRESS ?? "127.0.0.1";

  await app.listen(Number(port), host);

  logger.log(`🚀 Orchestrator running on http://${host}:${String(port)}`);
}

bootstrap().catch((err: unknown) => {
  logger.error("Failed to start orchestrator", err instanceof Error ? err.stack : String(err));
  process.exit(1);
});
