private async Task ProcessEstablishmentsAsync( long[] urns, DateTime pointInTime, bool managementGroupHasChanged, CancellationToken cancellationToken) { foreach (var urn in urns) { var previous = await _establishmentRepository.GetEstablishmentAsync(urn, pointInTime, cancellationToken); var staging = await _establishmentRepository.GetEstablishmentFromStagingAsync(urn, pointInTime, cancellationToken); if (previous == null) { _logger.Info($"Establishment {urn} has not been seen before {pointInTime}. Processing as created"); await StoreEstablishmentAndRaiseEventAsync(staging, false, cancellationToken); } else if (managementGroupHasChanged) { _logger.Info($"Management group of establishment {urn} on {pointInTime} has changed. Processing as updated"); await StoreEstablishmentAndRaiseEventAsync(staging, true, cancellationToken); } else if (!AreSame(previous, staging)) { _logger.Info($"Establishment {urn} on {pointInTime} has changed since {previous.PointInTime}. Processing as updated"); await StoreEstablishmentAndRaiseEventAsync(staging, true, cancellationToken); } else { _logger.Info($"Establishment {urn} on {pointInTime} has not changed since {previous.PointInTime}. Skipping"); } } }