import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { DatabaseModule } from '@it0/database';
import { AgentController } from './interfaces/rest/controllers/agent.controller';
import { SessionController } from './interfaces/rest/controllers/session.controller';
import { RiskRulesController } from './interfaces/rest/controllers/risk-rules.controller';
import { TenantAgentConfigController } from './interfaces/rest/controllers/tenant-agent-config.controller';
import { AgentConfigController } from './interfaces/rest/controllers/agent-config.controller';
import { SkillsController } from './interfaces/rest/controllers/skills.controller';
import { HooksController } from './interfaces/rest/controllers/hooks.controller';
import { AgentStreamGateway } from './interfaces/ws/agent-stream.gateway';
import { EngineRegistry } from './infrastructure/engines/engine-registry';
import { ClaudeCodeCliEngine } from './infrastructure/engines/claude-code-cli/claude-code-engine';
import { ClaudeApiEngine } from './infrastructure/engines/claude-api/claude-api-engine';
import { ClaudeAgentSdkEngine } from './infrastructure/engines/claude-agent-sdk';
import { ToolExecutor } from './infrastructure/engines/claude-api/tool-executor';
import { CommandGuardService } from './infrastructure/guards/command-guard.service';
import { SkillManagerService } from './domain/services/skill-manager.service';
import { StandingOrderExtractorService } from './domain/services/standing-order-extractor';
import { AllowedToolsResolverService } from './domain/services/allowed-tools-resolver.service';
import { SessionRepository } from './infrastructure/repositories/session.repository';
import { TaskRepository } from './infrastructure/repositories/task.repository';
import { TenantAgentConfigRepository } from './infrastructure/repositories/tenant-agent-config.repository';
import { AgentConfigRepository } from './infrastructure/repositories/agent-config.repository';
import { HookScriptRepository } from './infrastructure/repositories/hook-script.repository';
import { TenantAgentConfigService } from './infrastructure/services/tenant-agent-config.service';
import { AgentConfigService } from './infrastructure/services/agent-config.service';
import { AgentSkillService } from './infrastructure/services/agent-skill.service';
import { HookScriptService } from './infrastructure/services/hook-script.service';
import { AgentSession } from './domain/entities/agent-session.entity';
import { AgentTask } from './domain/entities/agent-task.entity';
import { CommandRecord } from './domain/entities/command-record.entity';
import { StandingOrderRef } from './domain/entities/standing-order.entity';
import { TenantAgentConfig } from './domain/entities/tenant-agent-config.entity';
import { AgentConfig } from './domain/entities/agent-config.entity';
import { HookScript } from './domain/entities/hook-script.entity';
import { VoiceConfig } from './domain/entities/voice-config.entity';
import { ConversationMessage } from './domain/entities/conversation-message.entity';
import { UsageRecord } from './domain/entities/usage-record.entity';
import { MessageRepository } from './infrastructure/repositories/message.repository';
import { VoiceConfigRepository } from './infrastructure/repositories/voice-config.repository';
import { UsageRecordRepository } from './infrastructure/repositories/usage-record.repository';
import { VoiceConfigService } from './infrastructure/services/voice-config.service';
import { VoiceConfigController } from './interfaces/rest/controllers/voice-config.controller';
import { VoiceSessionController } from './interfaces/rest/controllers/voice-session.controller';
import { ConversationContextService } from './domain/services/conversation-context.service';
import { VoiceSessionManager } from './domain/services/voice-session-manager.service';
import { EventPublisherService } from './infrastructure/messaging/event-publisher.service';
import { OpenAISttService } from './infrastructure/stt/openai-stt.service';
import { AgentInstance } from './domain/entities/agent-instance.entity';
import { AgentInstanceRepository } from './infrastructure/repositories/agent-instance.repository';
import { AgentInstanceDeployService } from './infrastructure/services/agent-instance-deploy.service';
import { AgentInstanceController } from './interfaces/rest/controllers/agent-instance.controller';
import { SystemPromptBuilder } from './infrastructure/engines/claude-code-cli/system-prompt-builder';

@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal: true }),
    DatabaseModule.forRoot(),
    TypeOrmModule.forFeature([
      AgentSession, AgentTask, CommandRecord, StandingOrderRef,
      TenantAgentConfig, AgentConfig, HookScript, VoiceConfig,
      ConversationMessage, UsageRecord, AgentInstance,
    ]),
  ],
  controllers: [
    AgentController, SessionController, RiskRulesController,
    TenantAgentConfigController, AgentConfigController, VoiceConfigController,
    VoiceSessionController, SkillsController, HooksController,
    AgentInstanceController,
  ],
  providers: [
    AgentStreamGateway,
    EngineRegistry,
    ClaudeCodeCliEngine,
    ClaudeApiEngine,
    ClaudeAgentSdkEngine,
    ToolExecutor,
    CommandGuardService,
    SkillManagerService,
    StandingOrderExtractorService,
    AllowedToolsResolverService,
    ConversationContextService,
    VoiceSessionManager,
    SessionRepository,
    TaskRepository,
    MessageRepository,
    UsageRecordRepository,
    TenantAgentConfigRepository,
    AgentConfigRepository,
    VoiceConfigRepository,
    HookScriptRepository,
    TenantAgentConfigService,
    AgentConfigService,
    VoiceConfigService,
    AgentSkillService,
    HookScriptService,
    EventPublisherService,
    OpenAISttService,
    AgentInstanceRepository,
    AgentInstanceDeployService,
    SystemPromptBuilder,
  ],
})
export class AgentModule {}
