import { CommandHandler, type ICommandHandler } from '@nestjs/cqrs';
import { type ListingIndexerService } from '../../../infrastructure/services/listing-indexer.service';
import { SyncListingCommand } from './sync-listing.command';

@CommandHandler(SyncListingCommand)
export class SyncListingHandler implements ICommandHandler<SyncListingCommand> {
  constructor(private readonly indexer: ListingIndexerService) {}

  async execute(command: SyncListingCommand): Promise<void> {
    await this.indexer.indexListing(command.listingId);
  }
}
