import { Module } from '@nestjs/common';
import { CqrsModule } from '@nestjs/cqrs';
import { CreateReviewHandler } from './application/commands/create-review/create-review.handler';
import { DeleteReviewHandler } from './application/commands/delete-review/delete-review.handler';
import { ReviewDeletedListener } from './application/listeners/review-deleted.listener';
import { GetAverageRatingHandler } from './application/queries/get-average-rating/get-average-rating.handler';
import { GetReviewsByTargetHandler } from './application/queries/get-reviews-by-target/get-reviews-by-target.handler';
import { GetReviewsByUserHandler } from './application/queries/get-reviews-by-user/get-reviews-by-user.handler';
import { REVIEW_REPOSITORY } from './domain/repositories/review.repository';
import { PrismaReviewRepository } from './infrastructure/repositories/prisma-review.repository';
import { ReviewsController } from './presentation/controllers/reviews.controller';

const CommandHandlers = [CreateReviewHandler, DeleteReviewHandler];

const QueryHandlers = [
  GetReviewsByTargetHandler,
  GetAverageRatingHandler,
  GetReviewsByUserHandler,
];

@Module({
  imports: [CqrsModule],
  controllers: [ReviewsController],
  providers: [
    { provide: REVIEW_REPOSITORY, useClass: PrismaReviewRepository },
    ...CommandHandlers,
    ...QueryHandlers,
    ReviewDeletedListener,
  ],
  exports: [REVIEW_REPOSITORY],
})
export class ReviewsModule {}
