import { Inject } from '@nestjs/common';
import { type IQueryHandler, QueryHandler } from '@nestjs/cqrs';
import { type ReviewItemData } from '../../../domain/repositories/review-read.dto';
import { REVIEW_REPOSITORY, type IReviewRepository, type PaginatedResult } from '../../../domain/repositories/review.repository';
import { GetReviewsByUserQuery } from './get-reviews-by-user.query';

@QueryHandler(GetReviewsByUserQuery)
export class GetReviewsByUserHandler implements IQueryHandler<GetReviewsByUserQuery> {
  constructor(
    @Inject(REVIEW_REPOSITORY) private readonly reviewRepo: IReviewRepository,
  ) {}

  async execute(query: GetReviewsByUserQuery): Promise<PaginatedResult<ReviewItemData>> {
    return this.reviewRepo.findByUserId(query.userId, query.page, query.limit);
  }
}
