import { Module, forwardRef } from '@nestjs/common';
import { PrismaModule } from '../../infrastructure/database/prisma.module';
import { OutboxRepository } from '../../infrastructure/outbox/outbox.repository';
import { AiRuntimeModule } from '../ai-runtime/ai-runtime.module';
import { AiModule } from '../ai/ai.module';
import { AiJobStateMachine } from './ai-job-state-machine';
import { AiJobLifecycleRepository } from './ai-job-lifecycle.repository';
import { JobDefinitionRegistry } from './job-definition-registry';
import { AiJobCreationService } from './ai-job-creation.service';
import { AiJobExecutionEngineImpl } from './ai-job-execution-engine';
import { AI_JOB_EXECUTION_ENGINE } from './ai-job-execution-engine.interface';
import { ProjectionExecutor } from './projection-executor.service';
import { SyntheticResultProjector } from './synthetic-result-projector';
import { RESULT_PROJECTORS } from './result-projector.interface';
import { AiJobController } from './ai-job.controller';
import { AiJobAdminController } from './ai-job-admin.controller';
import { AiJobService } from './ai-job.service';
import { SyntheticRegistrationService } from './synthetic-registration.service';
import { ActiveRecallRegistrationService } from './active-recall-registration.service';
import { ActiveRecallSnapshotBuilder } from './active-recall-snapshot-builder';
import { ActiveRecallExecutor } from './active-recall-executor';
import {
  ActiveRecallBusinessValidator,
  ActiveRecallReferenceValidator,
} from './active-recall-validator';
import { ActiveRecallProjector } from './active-recall-projector';
import { ActiveRecallExecutionRouter } from './active-recall-execution-router';
import { ActiveRecallObservabilityService } from './active-recall-observability.service';
import { FeynmanRegistrationService } from './feynman-registration.service';
import { FeynmanSnapshotBuilder } from './feynman-snapshot-builder';
import { FeynmanExecutor } from './feynman-executor';
import { ReviewCardGenerationRegistrationService } from './review-card-generation-registration.service';
import { ReviewCardGenerationSnapshotBuilder } from './review-card-generation-snapshot-builder';
import { ReviewCardGenerationExecutor } from './review-card-generation-executor';
import { ReviewCardGenerationValidator } from './review-card-generation-validator';
import { ReviewCardGenerationProjector } from './review-card-generation-projector';
import { QuizGenerationRegistrationService } from './quiz-generation-registration.service';
import { QuizGenerationSnapshotBuilder } from './quiz-generation-snapshot-builder';
import { QuizGenerationExecutor } from './quiz-generation-executor';
import { QuizGenerationValidator } from './quiz-generation-validator';
import { QuizGenerationProjector } from './quiz-generation-projector';
import { LearningAnalysisRegistrationService } from './learning-analysis-registration.service';
import { LearningAnalysisSnapshotBuilder } from './learning-analysis-snapshot-builder';
import { LearningAnalysisExecutor } from './learning-analysis-executor';
import { LearningAnalysisValidator } from './learning-analysis-validator';
import { LearningAnalysisProjector } from './learning-analysis-projector';
import {
  FeynmanBusinessValidator,
  FeynmanReferenceValidator,
} from './feynman-validator';
import { FeynmanProjector } from './feynman-projector';
import { FeynmanObservabilityService } from './feynman-observability.service';
import { AppConfigModule } from '../config/config.module';

@Module({
  imports: [PrismaModule, forwardRef(() => AiRuntimeModule), AiModule, AppConfigModule],
  controllers: [AiJobController, AiJobAdminController],
  providers: [
    AiJobStateMachine,
    AiJobLifecycleRepository,
    JobDefinitionRegistry,
    OutboxRepository,
    AiJobCreationService,
    AiJobService,
    AiJobExecutionEngineImpl,
    ProjectionExecutor,
    SyntheticRegistrationService,
    SyntheticResultProjector,
    ActiveRecallRegistrationService,
    ActiveRecallSnapshotBuilder,
    ActiveRecallExecutor,
    ActiveRecallBusinessValidator,
    ActiveRecallReferenceValidator,
    ActiveRecallProjector,
    ActiveRecallExecutionRouter,
    ActiveRecallObservabilityService,
    FeynmanRegistrationService,
    FeynmanSnapshotBuilder,
    FeynmanExecutor,
    FeynmanBusinessValidator,
    FeynmanReferenceValidator,
    FeynmanProjector,
    FeynmanObservabilityService,
    ReviewCardGenerationRegistrationService,
    ReviewCardGenerationSnapshotBuilder,
    ReviewCardGenerationExecutor,
    ReviewCardGenerationValidator,
    ReviewCardGenerationProjector,
    QuizGenerationRegistrationService,
    QuizGenerationSnapshotBuilder,
    QuizGenerationExecutor,
    QuizGenerationValidator,
    QuizGenerationProjector,
    LearningAnalysisRegistrationService,
    LearningAnalysisSnapshotBuilder,
    LearningAnalysisExecutor,
    LearningAnalysisValidator,
    LearningAnalysisProjector,
    { provide: RESULT_PROJECTORS, useFactory: (synthetic: SyntheticResultProjector, activeRecall: ActiveRecallProjector, feynman: FeynmanProjector, reviewCard: ReviewCardGenerationProjector, quiz: QuizGenerationProjector, learningAnalysis: LearningAnalysisProjector) => [synthetic, activeRecall, feynman, reviewCard, quiz, learningAnalysis], inject: [SyntheticResultProjector, ActiveRecallProjector, FeynmanProjector, ReviewCardGenerationProjector, QuizGenerationProjector, LearningAnalysisProjector] } as any,
    { provide: AI_JOB_EXECUTION_ENGINE, useExisting: AiJobExecutionEngineImpl },
  ],
  exports: [
    AiJobStateMachine,
    AiJobLifecycleRepository,
    JobDefinitionRegistry,
    AiJobCreationService,
    ActiveRecallExecutionRouter,
    ActiveRecallObservabilityService,
    FeynmanSnapshotBuilder,
    FeynmanObservabilityService,
    QuizGenerationSnapshotBuilder,
    LearningAnalysisSnapshotBuilder,
    AI_JOB_EXECUTION_ENGINE,
  ],
})
export class AiJobModule {}
