import { Module } from "@nestjs/common";
import { BullModule } from "@nestjs/bullmq";
import { PrismaModule } from "../prisma/prisma.module";
import { AuthModule } from "../auth/auth.module";
import { OllamaModule } from "../ollama/ollama.module";
import { KnowledgeService } from "./knowledge.service";
import {
  KnowledgeController,
  KnowledgeCacheController,
  KnowledgeEmbeddingsController,
} from "./knowledge.controller";
import { SearchController } from "./search.controller";
import { KnowledgeStatsController } from "./stats.controller";
import { KnowledgeGraphController } from "./graph.controller";
import {
  LinkResolutionService,
  SearchService,
  LinkSyncService,
  GraphService,
  StatsService,
  KnowledgeCacheService,
  EmbeddingService,
} from "./services";
import { OllamaEmbeddingService } from "./services/ollama-embedding.service";
import { EmbeddingQueueService } from "./queues/embedding-queue.service";
import { EmbeddingProcessor } from "./queues/embedding.processor";

@Module({
  imports: [
    PrismaModule,
    AuthModule,
    OllamaModule,
    BullModule.registerQueue({
      name: "embeddings",
      defaultJobOptions: {
        attempts: 3,
        backoff: {
          type: "exponential",
          delay: 5000,
        },
      },
    }),
  ],
  controllers: [
    KnowledgeController,
    KnowledgeCacheController,
    KnowledgeEmbeddingsController,
    SearchController,
    KnowledgeStatsController,
    KnowledgeGraphController,
  ],
  providers: [
    KnowledgeService,
    LinkResolutionService,
    SearchService,
    LinkSyncService,
    GraphService,
    StatsService,
    KnowledgeCacheService,
    EmbeddingService,
    OllamaEmbeddingService,
    EmbeddingQueueService,
    EmbeddingProcessor,
  ],
  exports: [
    KnowledgeService,
    LinkResolutionService,
    SearchService,
    EmbeddingService,
    OllamaEmbeddingService,
    EmbeddingQueueService,
  ],
})
export class KnowledgeModule {}
