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

export interface ReindexResult {
  indexed: number;
  total: number;
}

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

  async execute(): Promise<ReindexResult> {
    return this.indexer.reindexAll();
  }
}
