import { Inject } from '@nestjs/common';
import { type IQueryHandler, QueryHandler } from '@nestjs/cqrs';
import {
  TRANSFER_LISTING_REPOSITORY,
  type ITransferListingRepository,
} from '../../../domain/repositories/transfer-listing.repository';
import { ListPendingTransfersQuery } from './list-pending-transfers.query';

@QueryHandler(ListPendingTransfersQuery)
export class ListPendingTransfersHandler implements IQueryHandler<ListPendingTransfersQuery> {
  constructor(
    @Inject(TRANSFER_LISTING_REPOSITORY)
    private readonly repo: ITransferListingRepository,
  ) {}

  async execute(query: ListPendingTransfersQuery) {
    return this.repo.search({
      status: 'PENDING_REVIEW',
      page: query.page,
      limit: query.limit,
    });
  }
}
