import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConversationORM } from '../infrastructure/database/postgres/entities/conversation.orm';
import { MessageORM } from '../infrastructure/database/postgres/entities/message.orm';
import { TokenUsageORM } from '../infrastructure/database/postgres/entities/token-usage.orm';
import { AgentExecutionORM } from '../infrastructure/database/postgres/entities/agent-execution.orm';
import { ConversationPostgresRepository } from '../adapters/outbound/persistence/conversation-postgres.repository';
import { MessagePostgresRepository } from '../adapters/outbound/persistence/message-postgres.repository';
import { TokenUsagePostgresRepository } from '../adapters/outbound/persistence/token-usage-postgres.repository';
import { CONVERSATION_REPOSITORY } from '../domain/repositories/conversation.repository.interface';
import { MESSAGE_REPOSITORY } from '../domain/repositories/message.repository.interface';
import { TOKEN_USAGE_REPOSITORY } from '../domain/repositories/token-usage.repository.interface';
import { ConversationService } from '../application/services/conversation.service';
import { ConversationController } from '../adapters/inbound/conversation.controller';
import { InternalConversationController } from '../adapters/inbound/internal.controller';
import { AdminConversationController } from '../adapters/inbound/admin-conversation.controller';
import { AdminMcpController } from '../adapters/inbound/admin-mcp.controller';
import { AdminEvaluationRuleController } from '../adapters/inbound/admin-evaluation-rule.controller';
import { ConversationGateway } from '../adapters/inbound/conversation.gateway';

@Module({
  imports: [TypeOrmModule.forFeature([ConversationORM, MessageORM, TokenUsageORM, AgentExecutionORM])],
  controllers: [ConversationController, InternalConversationController, AdminMcpController, AdminEvaluationRuleController, AdminConversationController],
  providers: [
    ConversationService,
    ConversationGateway,
    {
      provide: CONVERSATION_REPOSITORY,
      useClass: ConversationPostgresRepository,
    },
    {
      provide: MESSAGE_REPOSITORY,
      useClass: MessagePostgresRepository,
    },
    {
      provide: TOKEN_USAGE_REPOSITORY,
      useClass: TokenUsagePostgresRepository,
    },
  ],
  exports: [ConversationService, CONVERSATION_REPOSITORY, MESSAGE_REPOSITORY, TOKEN_USAGE_REPOSITORY],
})
export class ConversationModule {}
