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 { ListTransferListingsQuery } from './list-transfer-listings.query';

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

  async execute(query: ListTransferListingsQuery) {
    return this.repo.search({
      query: query.query,
      category: query.category,
      status: query.status,
      district: query.district,
      city: query.city,
      minPrice: query.minPrice,
      maxPrice: query.maxPrice,
      sellerId: query.sellerId,
      page: query.page,
      limit: query.limit,
    });
  }
}
