import { Module } from '@nestjs/common';
import { CqrsModule } from '@nestjs/cqrs';
import { AuthModule } from '@modules/auth';
import { ListingsModule } from '@modules/listings';
import { SubscriptionsModule } from '@modules/subscriptions';
import { AdjustSubscriptionHandler } from './application/commands/adjust-subscription/adjust-subscription.handler';
import { ApproveKycHandler } from './application/commands/approve-kyc/approve-kyc.handler';
import { ApproveListingHandler } from './application/commands/approve-listing/approve-listing.handler';
import { BanUserHandler } from './application/commands/ban-user/ban-user.handler';
import { BulkModerateListingsHandler } from './application/commands/bulk-moderate-listings/bulk-moderate-listings.handler';
import { RejectKycHandler } from './application/commands/reject-kyc/reject-kyc.handler';
import { RejectListingHandler } from './application/commands/reject-listing/reject-listing.handler';
import { UpdateUserStatusHandler } from './application/commands/update-user-status/update-user-status.handler';
import { UserBannedListener } from './application/listeners/user-banned.listener';
import { UserDeactivatedListener } from './application/listeners/user-deactivated.listener';
import { GetDashboardStatsHandler } from './application/queries/get-dashboard-stats/get-dashboard-stats.handler';
import { GetKycQueueHandler } from './application/queries/get-kyc-queue/get-kyc-queue.handler';
import { GetModerationQueueHandler } from './application/queries/get-moderation-queue/get-moderation-queue.handler';
import { GetRevenueStatsHandler } from './application/queries/get-revenue-stats/get-revenue-stats.handler';
import { GetUserDetailHandler } from './application/queries/get-user-detail/get-user-detail.handler';
import { GetUsersHandler } from './application/queries/get-users/get-users.handler';
import { ADMIN_QUERY_REPOSITORY } from './domain/repositories/admin-query.repository';
import { PrismaAdminQueryRepository } from './infrastructure/repositories/prisma-admin-query.repository';
import { AdminModerationController } from './presentation/controllers/admin-moderation.controller';
import { AdminController } from './presentation/controllers/admin.controller';

const CommandHandlers = [
  ApproveListingHandler,
  RejectListingHandler,
  BanUserHandler,
  AdjustSubscriptionHandler,
  UpdateUserStatusHandler,
  ApproveKycHandler,
  RejectKycHandler,
  BulkModerateListingsHandler,
];

const QueryHandlers = [
  GetModerationQueueHandler,
  GetDashboardStatsHandler,
  GetRevenueStatsHandler,
  GetUsersHandler,
  GetUserDetailHandler,
  GetKycQueueHandler,
];

@Module({
  imports: [CqrsModule, AuthModule, ListingsModule, SubscriptionsModule],
  controllers: [AdminController, AdminModerationController],
  providers: [
    // Repositories
    { provide: ADMIN_QUERY_REPOSITORY, useClass: PrismaAdminQueryRepository },

    // CQRS
    ...CommandHandlers,
    ...QueryHandlers,

    // Event Listeners
    UserBannedListener,
    UserDeactivatedListener,
  ],
})
export class AdminModule {}
