import { Inject } from '@nestjs/common';
import { QueryHandler, type IQueryHandler } from '@nestjs/cqrs';
import { type ListingSearchItem } from '../../../domain/repositories/listing-read.dto';
import { LISTING_REPOSITORY, type IListingRepository, type PaginatedResult } from '../../../domain/repositories/listing.repository';
import { GetPendingModerationQuery } from './get-pending-moderation.query';

@QueryHandler(GetPendingModerationQuery)
export class GetPendingModerationHandler implements IQueryHandler<GetPendingModerationQuery> {
  constructor(
    @Inject(LISTING_REPOSITORY) private readonly listingRepo: IListingRepository,
  ) {}

  async execute(query: GetPendingModerationQuery): Promise<PaginatedResult<ListingSearchItem>> {
    return this.listingRepo.findByStatus('PENDING_REVIEW', query.page, query.limit);
  }
}
