import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { KnowledgeController } from '../adapters/inbound/knowledge.controller';
import { KnowledgeService } from '../application/services/knowledge.service';
import { RAGService } from '../application/services/rag.service';
import { ChunkingService } from '../application/services/chunking.service';
import { EmbeddingService } from '../infrastructure/embedding/embedding.service';
import { TextExtractionService } from '../application/services/text-extraction.service';
import { KnowledgePostgresRepository } from '../adapters/outbound/persistence/knowledge-postgres.repository';
import {
  UserMemoryPostgresRepository,
  SystemExperiencePostgresRepository,
} from '../adapters/outbound/persistence/memory-postgres.repository';
import { KnowledgeArticleORM } from '../infrastructure/database/postgres/entities/knowledge-article.orm';
import { KnowledgeChunkORM } from '../infrastructure/database/postgres/entities/knowledge-chunk.orm';
import { UserMemoryORM } from '../infrastructure/database/postgres/entities/user-memory.orm';
import { SystemExperienceORM } from '../infrastructure/database/postgres/entities/system-experience.orm';
import { KNOWLEDGE_REPOSITORY } from '../domain/repositories/knowledge.repository.interface';
import {
  USER_MEMORY_REPOSITORY,
  SYSTEM_EXPERIENCE_REPOSITORY,
} from '../domain/repositories/memory.repository.interface';

@Module({
  imports: [
    TypeOrmModule.forFeature([
      KnowledgeArticleORM,
      KnowledgeChunkORM,
      UserMemoryORM,
      SystemExperienceORM,
    ]),
  ],
  controllers: [KnowledgeController],
  providers: [
    KnowledgeService,
    RAGService,
    ChunkingService,
    EmbeddingService,
    TextExtractionService,
    {
      provide: KNOWLEDGE_REPOSITORY,
      useClass: KnowledgePostgresRepository,
    },
    {
      provide: USER_MEMORY_REPOSITORY,
      useClass: UserMemoryPostgresRepository,
    },
    {
      provide: SYSTEM_EXPERIENCE_REPOSITORY,
      useClass: SystemExperiencePostgresRepository,
    },
  ],
  exports: [KnowledgeService, RAGService, EmbeddingService],
})
export class KnowledgeModule {}
