import { Processor, WorkerHost } from '@nestjs/bullmq';
import { Injectable } from '@nestjs/common';
import { Job } from 'bullmq';
import { QUEUE_NAMES } from '../../common/constants/events';
import { MapMatchingService } from '../../map-matching/map-matching.service';
import type { MatchReason } from '../../map-matching/schemas/match-job.schema';

@Injectable()
@Processor(QUEUE_NAMES.MAP_MATCHING)
export class MapMatchingProcessor extends WorkerHost {

  constructor(private readonly mapMatching: MapMatchingService) {
    super();
  }

  async process(job: Job<{ tripId: string; reason?: MatchReason }>) {
    return this.mapMatching.runMatch(
      job.data.tripId,
      job.data.reason ?? 'manual',
    );
  }
}
