import { listingsApi, type ListingDetail } from './listings-api';

/**
 * Fetch multiple listing details in parallel for comparison.
 * Returns only successfully fetched listings (silently skips 404s).
 */
export async function fetchListingsForComparison(
  ids: string[],
): Promise<ListingDetail[]> {
  const results = await Promise.allSettled(ids.map((id) => listingsApi.getById(id)));

  return results
    .filter((r): r is PromiseFulfilledResult<ListingDetail> => r.status === 'fulfilled')
    .map((r) => r.value);
}
