import { Module } from '@nestjs/common';
import { CqrsModule } from '@nestjs/cqrs';
import { SendNotificationHandler } from './application/commands/send-notification/send-notification.handler';
import { AgentVerifiedListener } from './application/listeners/agent-verified.listener';
import { InquiryReceivedListener } from './application/listeners/inquiry-received.listener';
import { ListingApprovedListener } from './application/listeners/listing-approved.listener';
import { ListingRejectedListener } from './application/listeners/listing-rejected.listener';
import { PaymentCompletedListener } from './application/listeners/payment-completed.listener';
import { QuotaExceededListener } from './application/listeners/quota-exceeded.listener';
import { SubscriptionExpiringListener } from './application/listeners/subscription-expiring.listener';
import { UserRegisteredListener } from './application/listeners/user-registered.listener';
import { NOTIFICATION_PREFERENCE_REPOSITORY } from './domain/repositories/notification-preference.repository';
import { NOTIFICATION_REPOSITORY } from './domain/repositories/notification.repository';
import { PrismaNotificationPreferenceRepository } from './infrastructure/repositories/prisma-notification-preference.repository';
import { PrismaNotificationRepository } from './infrastructure/repositories/prisma-notification.repository';
import { EmailService } from './infrastructure/services/email.service';
import { FcmService } from './infrastructure/services/fcm.service';
import { TemplateService } from './infrastructure/services/template.service';
import { NotificationsController } from './presentation/controllers/notifications.controller';

const CommandHandlers = [SendNotificationHandler];

const EventListeners = [
  UserRegisteredListener,
  AgentVerifiedListener,
  QuotaExceededListener,
  ListingApprovedListener,
  ListingRejectedListener,
  PaymentCompletedListener,
  SubscriptionExpiringListener,
  InquiryReceivedListener,
];

@Module({
  imports: [CqrsModule],
  controllers: [NotificationsController],
  providers: [
    // Repositories
    { provide: NOTIFICATION_REPOSITORY, useClass: PrismaNotificationRepository },
    { provide: NOTIFICATION_PREFERENCE_REPOSITORY, useClass: PrismaNotificationPreferenceRepository },

    // Services
    EmailService,
    FcmService,
    TemplateService,

    // CQRS
    ...CommandHandlers,

    // Event Listeners
    ...EventListeners,
  ],
  exports: [EmailService, FcmService, TemplateService],
})
export class NotificationsModule {}
