import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { APP_GUARD } from '@nestjs/core';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AppController } from './app.controller';
import { AuthController } from './auth/auth.controller';
import { AgentController } from './agent/agent.controller';
import { DashboardController } from './dashboard/dashboard.controller';
import { TasksController } from './tasks/tasks.controller';
import { RunsController } from './runs/runs.controller';
import { IncidentsController } from './incidents/incidents.controller';
import { AgentService } from './agent/agent.service';
import { AuthService } from './auth/auth.service';
import { SessionGuard } from './auth/session.guard';
import { DashboardService } from './dashboard/dashboard.service';
import { TasksService } from './tasks/tasks.service';
import { RunsService } from './runs/runs.service';
import { InspectorService } from './inspector/inspector.service';
import { buildDatabaseOptions } from './database/database.config';
import { InspectionTaskEntity } from './tasks/inspection-task.entity';
import { InspectionRunEntity } from './runs/inspection-run.entity';
import { TaskSchedulerService } from './scheduler/task-scheduler.service';
import { BrowserExecutorService } from './executors/browser-executor.service';
import { AgentExecutorService } from './executors/agent-executor.service';
import { ExecutionRouterService } from './executors/execution-router.service';
import { MonitorLogEventEntity } from './monitoring/monitor-log-event.entity';
import { MonitorAgentEntity } from './monitoring/monitor-agent.entity';
import { MonitorTargetEntity } from './monitoring/monitor-target.entity';
import { MonitorRunEntity } from './monitoring/monitor-run.entity';
import { MonitorAlertEntity } from './monitoring/monitor-alert.entity';
import { MonitoringController } from './monitoring/monitoring.controller';
import { MonitoringService } from './monitoring/monitoring.service';
import { MonitoringSchedulerService } from './monitoring/monitoring-scheduler.service';
import { LogAnalysisService } from './monitoring/log-analysis.service';
import { OpenObserveLogAdapter } from './monitoring/openobserve-log.adapter';
import { Drain3Adapter } from './monitoring/drain3.adapter';
import { MonitorAlertService } from './monitoring/monitor-alert.service';
import { MonitorAlertNotificationService } from './monitoring/monitor-alert-notification.service';
import { IncidentCaseEntity } from './incidents/incident-case.entity';
import { IncidentsService } from './incidents/incidents.service';

@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal: true }),
    TypeOrmModule.forRootAsync({
      inject: [ConfigService],
      useFactory: (configService: ConfigService) =>
        buildDatabaseOptions(configService),
    }),
    TypeOrmModule.forFeature([
      InspectionTaskEntity,
      InspectionRunEntity,
      IncidentCaseEntity,
      MonitorAgentEntity,
      MonitorLogEventEntity,
      MonitorTargetEntity,
      MonitorRunEntity,
      MonitorAlertEntity,
    ]),
  ],
  controllers: [
    AppController,
    AuthController,
    AgentController,
    DashboardController,
    TasksController,
    RunsController,
    MonitoringController,
    IncidentsController,
  ],
  providers: [
    AuthService,
    AgentService,
    DashboardService,
    TasksService,
    RunsService,
    InspectorService,
    BrowserExecutorService,
    AgentExecutorService,
    ExecutionRouterService,
    TaskSchedulerService,
    MonitoringService,
    MonitoringSchedulerService,
    LogAnalysisService,
    OpenObserveLogAdapter,
    Drain3Adapter,
    MonitorAlertService,
    MonitorAlertNotificationService,
    IncidentsService,
    {
      provide: APP_GUARD,
      useClass: SessionGuard,
    },
  ],
})
export class AppModule {}
