import { Injectable, Logger, OnModuleInit } from '@nestjs/common';
import { JobDefinitionRegistry, DuplicateJobTypeError } from './job-definition-registry';
import { LEARNING_ANALYSIS_JOB_DEFINITION } from './learning-analysis-job-definition';

@Injectable()
export class LearningAnalysisRegistrationService implements OnModuleInit {
  private readonly logger = new Logger(LearningAnalysisRegistrationService.name);
  constructor(private readonly registry: JobDefinitionRegistry) {}

  onModuleInit(): void {
    try {
      this.registry.register(LEARNING_ANALYSIS_JOB_DEFINITION);
      this.logger.log(`Learning Analysis Definition registered: jobType=learning_analysis queue=ai-background`);
    } catch (err: unknown) {
      if (err instanceof DuplicateJobTypeError) {
        this.logger.log('Learning Analysis Definition already registered (dual process)');
      } else { throw err; }
    }
  }
}
