import { Injectable, Logger } from "@nestjs/common";
import { InjectQueue } from "@nestjs/bullmq";
import { Queue } from "bullmq";
import {
  PREDICTIONS_QUEUE,
  PredictionJobType,
  PredictMatchJobData,
  SmartCouponJobData,
} from "./predictions.types";

@Injectable()
export class PredictionsQueue {
  private readonly logger = new Logger(PredictionsQueue.name);

  constructor(
    @InjectQueue(PREDICTIONS_QUEUE)
    public readonly queue: Queue,
  ) {}

  /**
   * Add a single match prediction job
   */
  async addPredictMatchJob(data: PredictMatchJobData) {
    this.logger.debug(`Adding prediction job for match: ${data.matchId}`);
    return this.queue.add(PredictionJobType.PREDICT_MATCH, data, {
      priority: 1, // High priority
    });
  }

  /**
   * Add a smart coupon generation job
   */
  async addSmartCouponJob(data: SmartCouponJobData) {
    this.logger.debug(
      `Adding smart coupon job: ${data.strategy} (${data.matchIds.length} matches)`,
    );
    return this.queue.add(PredictionJobType.SMART_COUPON, data, {
      priority: 5, // Lower priority than single predictions
    });
  }
}
