import { NestFactory } from "@nestjs/core";
import { AppModule } from "../app.module";
import { Logger } from "@nestjs/common";
import { DataFetcherTask } from "../tasks/data-fetcher.task";

async function bootstrap() {
  const logger = new Logger("LiveFeederShell");
  console.log("🚀 Starting Manual Live Feeder Update (Console)...");
  logger.log("🚀 Starting Manual Live Feeder Update...");

  const app = await NestFactory.createApplicationContext(AppModule, {
    logger: ["log", "error", "warn"],
  });

  try {
    const dataFetcherTask = app.get(DataFetcherTask);

    // Run full sync (matches + live scores + odds + lineups)
    logger.log("⚽🏀 Running full live match sync...");
    await dataFetcherTask.syncLiveMatches();

    logger.log("✅ Live Feeder update completed successfully!");
  } catch (error: any) {
    logger.error(`❌ Live Feeder failed: ${error.message}`);
    console.error(error.stack);
  } finally {
    await app.close();
  }
}

void bootstrap();
