public List <ProviderRecordStructure> GetAllProviders(List <string> ukprnList)
        {
            string[] statusesToFetch =
            {
                "A",     // Active
                //"V", // Verified. Omitted, we suspect this may be a subset of Active providers
                //"PD1", // Deactivation in process
                //"PD2" // Deactivation complete
            };

            List <ProviderRecordStructure> results = new List <ProviderRecordStructure>();

            int chunkSize  = 300;
            var noOfChunks = Math.Ceiling((double)ukprnList.Count / chunkSize);

            // Get UKRLP data in chunks at a time as API does not support large requests.
            for (int i = 0; i < noOfChunks; i++)
            {
                foreach (String status in statusesToFetch)
                {
                    var request = BuildRequest(ukprnList.Skip(i * chunkSize).Take(chunkSize).ToArray());
                    request.SelectionCriteria.ProviderStatus = status;
                    request.QueryId = GetNextQueryId();

                    var providerClient = new ProviderQueryPortTypeClient();
                    providerClient.InnerChannel.OperationTimeout = new TimeSpan(0, 10, 0);
                    Task <response> x = providerClient.retrieveAllProvidersAsync(request);
                    x.Wait();

                    results.AddRange(x.Result?.ProviderQueryResponse?.MatchingProviderRecords ?? new ProviderRecordStructure[] { });
                }
            }

            return(results.ToList());
        }
        public List <ProviderRecordStructure> SynchroniseProviders(DateTime dtLastUpdate, ILogger log)
        {
            string[] statusesToFetch =
            {
                "A",     // Active
                //"V", // Verified                      // Omitted, we suspect this may be a subset of Active providers
                "PD1",   // Deactivation in process
                "PD2"    // Deactivation complete
            };

            List <ProviderRecordStructure> results = new List <ProviderRecordStructure>();
            var request = Request(dtLastUpdate);

            foreach (String status in statusesToFetch)
            {
                log.LogInformation($"Downloading providers from UKRLP service with status {status}");

                request.SelectionCriteria.ProviderStatus = status;
                request.QueryId = GetNextQueryId();

                var pqp = new ProviderQueryParam {
                    ProviderQueryRequest = request
                };
                var             retrieveall = new ProviderQueryPortTypeClient();
                Task <response> x           = retrieveall.retrieveAllProvidersAsync(request);
                x.Wait();

                log.LogInformation($"UKRLP service returned {x.Result?.ProviderQueryResponse?.MatchingProviderRecords?.LongLength ?? 0} providers with status {status}");
                results.AddRange(x.Result?.ProviderQueryResponse?.MatchingProviderRecords ?? new ProviderRecordStructure[] { });
            }
            return(results);
        }