import { Module } from '@nestjs/common';
import { CqrsModule } from '@nestjs/cqrs';
import { InquiryCreatedToLeadListener } from './application/event-handlers/inquiry-created-to-lead.listener';
import { CreateLeadHandler } from './application/commands/create-lead/create-lead.handler';
import { DeleteLeadHandler } from './application/commands/delete-lead/delete-lead.handler';
import { UpdateLeadStatusHandler } from './application/commands/update-lead-status/update-lead-status.handler';
import { GetLeadStatsHandler } from './application/queries/get-lead-stats/get-lead-stats.handler';
import { GetLeadsByAgentHandler } from './application/queries/get-leads-by-agent/get-leads-by-agent.handler';
import { LEAD_REPOSITORY } from './domain/repositories/lead.repository';
import { PrismaLeadRepository } from './infrastructure/repositories/prisma-lead.repository';
import { LeadsController } from './presentation/controllers/leads.controller';

const CommandHandlers = [CreateLeadHandler, UpdateLeadStatusHandler, DeleteLeadHandler];

const QueryHandlers = [GetLeadsByAgentHandler, GetLeadStatsHandler];

const EventHandlers = [InquiryCreatedToLeadListener];

@Module({
  imports: [CqrsModule],
  controllers: [LeadsController],
  providers: [
    { provide: LEAD_REPOSITORY, useClass: PrismaLeadRepository },
    ...CommandHandlers,
    ...QueryHandlers,
    ...EventHandlers,
  ],
  exports: [LEAD_REPOSITORY],
})
export class LeadsModule {}
