import { Module } from "@nestjs/common";
import { HttpModule } from "@nestjs/axios";
import { BullModule } from "@nestjs/bullmq";
import { PredictionsController } from "./predictions.controller";
import { PredictionsService } from "./predictions.service";
import { AiFeatureStoreService } from "./services/ai-feature-store.service";
import { DatabaseModule } from "../../database/database.module";
import { MatchesModule } from "../matches/matches.module";
import { PredictionsQueue } from "./queues/predictions.queue";
import { PredictionsProcessor } from "./queues/predictions.processor";
import { PREDICTIONS_QUEUE } from "./queues/predictions.types";
import { FeederModule } from "../feeder/feeder.module";
import { AnalysisModule } from "../analysis/analysis.module";

const redisEnabled = process.env.REDIS_ENABLED === "true";

@Module({
  imports: [
    DatabaseModule,
    HttpModule.register({
      timeout: 30000, // 30 seconds
      maxRedirects: 5,
    }),
    ...(redisEnabled
      ? [BullModule.registerQueue({ name: PREDICTIONS_QUEUE })]
      : []),
    MatchesModule,
    FeederModule,
    AnalysisModule,
  ],
  controllers: [PredictionsController],
  providers: [
    PredictionsService,
    AiFeatureStoreService,
    ...(redisEnabled ? [PredictionsQueue, PredictionsProcessor] : []),
  ],
  exports: [PredictionsService, AiFeatureStoreService],
})
export class PredictionsModule {}
