import { Module } from '@nestjs/common';
import { CqrsModule } from '@nestjs/cqrs';
import { GenerateReportHandler } from './application/commands/generate-report/generate-report.handler';
import { TrackEventHandler } from './application/commands/track-event/track-event.handler';
import { UpdateMarketIndexHandler } from './application/commands/update-market-index/update-market-index.handler';
import { GetDistrictStatsHandler } from './application/queries/get-district-stats/get-district-stats.handler';
import { GetHeatmapHandler } from './application/queries/get-heatmap/get-heatmap.handler';
import { GetMarketReportHandler } from './application/queries/get-market-report/get-market-report.handler';
import { GetPriceTrendHandler } from './application/queries/get-price-trend/get-price-trend.handler';
import { MARKET_INDEX_REPOSITORY } from './domain/repositories/market-index.repository';
import { VALUATION_REPOSITORY } from './domain/repositories/valuation.repository';
import { PrismaMarketIndexRepository } from './infrastructure/repositories/prisma-market-index.repository';
import { PrismaValuationRepository } from './infrastructure/repositories/prisma-valuation.repository';
import { AnalyticsController } from './presentation/controllers/analytics.controller';

const CommandHandlers = [
  TrackEventHandler,
  GenerateReportHandler,
  UpdateMarketIndexHandler,
];

const QueryHandlers = [
  GetMarketReportHandler,
  GetHeatmapHandler,
  GetPriceTrendHandler,
  GetDistrictStatsHandler,
];

@Module({
  imports: [CqrsModule],
  controllers: [AnalyticsController],
  providers: [
    // Repositories
    { provide: MARKET_INDEX_REPOSITORY, useClass: PrismaMarketIndexRepository },
    { provide: VALUATION_REPOSITORY, useClass: PrismaValuationRepository },

    // CQRS
    ...CommandHandlers,
    ...QueryHandlers,
  ],
  exports: [MARKET_INDEX_REPOSITORY, VALUATION_REPOSITORY],
})
export class AnalyticsModule {}
