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 { AgentSkillRepository } from './infrastructure/repositories/agent-skill.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 { AgentSkill } from './domain/entities/agent-skill.entity';
import { HookScript } from './domain/entities/hook-script.entity';

@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal: true }),
    DatabaseModule.forRoot(),
    TypeOrmModule.forFeature([
      AgentSession, AgentTask, CommandRecord, StandingOrderRef,
      TenantAgentConfig, AgentConfig, AgentSkill, HookScript,
    ]),
  ],
  controllers: [
    AgentController, SessionController, RiskRulesController,
    TenantAgentConfigController, AgentConfigController, SkillsController, HooksController,
  ],
  providers: [
    AgentStreamGateway,
    EngineRegistry,
    ClaudeCodeCliEngine,
    ClaudeApiEngine,
    ClaudeAgentSdkEngine,
    ToolExecutor,
    CommandGuardService,
    SkillManagerService,
    StandingOrderExtractorService,
    AllowedToolsResolverService,
    SessionRepository,
    TaskRepository,
    TenantAgentConfigRepository,
    AgentConfigRepository,
    AgentSkillRepository,
    HookScriptRepository,
    TenantAgentConfigService,
    AgentConfigService,
    AgentSkillService,
    HookScriptService,
  ],
})
export class AgentModule {}
