import { Module } from '@nestjs/common';
import { CqrsModule } from '@nestjs/cqrs';
import { SearchModule } from '@modules/search';
import { CreateTransferListingHandler } from './application/commands/create-transfer-listing/create-transfer-listing.handler';
import { DeleteTransferListingHandler } from './application/commands/delete-transfer-listing/delete-transfer-listing.handler';
import { EstimateFromPhotosHandler } from './application/commands/estimate-from-photos/estimate-from-photos.handler';
import { EstimateTransferPricesHandler } from './application/commands/estimate-transfer-prices/estimate-transfer-prices.handler';
import { UpdateTransferListingHandler } from './application/commands/update-transfer-listing/update-transfer-listing.handler';
import { GetTransferListingHandler } from './application/queries/get-transfer-listing/get-transfer-listing.handler';
import { ListTransferListingsHandler } from './application/queries/list-transfer-listings/list-transfer-listings.handler';
import { TransferStatsHandler } from './application/queries/transfer-stats/transfer-stats.handler';
import { TRANSFER_LISTING_REPOSITORY } from './domain/repositories/transfer-listing.repository';
import { TransferListingTypesenseHandler } from './infrastructure/event-handlers/transfer-listing-typesense.handler';
import { PrismaTransferListingRepository } from './infrastructure/repositories/prisma-transfer-listing.repository';
import { CLAUDE_VISION_SERVICE, ClaudeVisionService } from './infrastructure/services/claude-vision.service';
import { TypesenseTransferService } from './infrastructure/services/typesense-transfer.service';
import { TransferController } from './presentation/controllers/transfer.controller';

const CommandHandlers = [
  CreateTransferListingHandler,
  DeleteTransferListingHandler,
  EstimateFromPhotosHandler,
  EstimateTransferPricesHandler,
  UpdateTransferListingHandler,
];

const QueryHandlers = [
  GetTransferListingHandler,
  ListTransferListingsHandler,
  TransferStatsHandler,
];

const EventHandlers = [
  TransferListingTypesenseHandler,
];

@Module({
  imports: [CqrsModule, SearchModule],
  controllers: [TransferController],
  providers: [
    { provide: TRANSFER_LISTING_REPOSITORY, useClass: PrismaTransferListingRepository },
    { provide: CLAUDE_VISION_SERVICE, useClass: ClaudeVisionService },
    TypesenseTransferService,
    ...CommandHandlers,
    ...QueryHandlers,
    ...EventHandlers,
  ],
  exports: [TRANSFER_LISTING_REPOSITORY, TypesenseTransferService],
})
export class TransferModule {}
