private void EnrichProvidedData(BankDataSheet data, List <AllegroDataContainer> allAllegroData,
                                        Action <BankDataSheet> completionCallback)
        {
            List <BankEntry> allUpdatedEntries = new List <BankEntry>();
            RefundEnricher   refunds           = new RefundEnricher(this.logger);
            PurchaseEnricher purchases         = new PurchaseEnricher(this.logger);

            foreach (BankEntry entry in data.Entries)
            {
                List <BankEntry> newEntries = ExtractAllegroEntries(entry, refunds, allAllegroData, purchases);
                allUpdatedEntries.AddRange(newEntries);
            }

            data.Entries = allUpdatedEntries;
            completionCallback(data);
        }
        private List <BankEntry> ExtractAllegroEntries(BankEntry entry, RefundEnricher refunds, List <AllegroDataContainer> allData,
                                                       PurchaseEnricher purchases)
        {
            if (IsAllegro(entry))
            {
                List <BankEntry> entriesForThisPayment = new List <BankEntry>();

                decimal buyerPaidAmount = 0;
                if (entry.Amount > 0)
                {
                    refunds.EnrichAllegroEntry(entry, allData, entriesForThisPayment, out buyerPaidAmount);
                }
                else
                {
                    purchases.EnrichAllegroEntry(entry, allData, entriesForThisPayment, out buyerPaidAmount);
                    if (buyerPaidAmount != entry.Amount)
                    {
                        if (!entry.Note.Contains(UnrecognizedEntry))
                        {
                            this.logger.Error("ERROR", new InvalidOperationException(
                                                  "Incorrect result of Allegro entry enriching. Original entry will be returned." +
                                                  $"The sum of {entriesForThisPayment.Count} new entries ({buyerPaidAmount}) plus sum of discounts ({buyerPaidAmount}) is different than the original entry amount. {entry}." +
                                                  $"New entries: {string.Join("\r\n", entriesForThisPayment.Select(x => x.ToString()))}"));
                            return(new List <BankEntry>()
                            {
                                entry
                            });
                        }
                    }
                }



                return(entriesForThisPayment);
            }
            else
            {
                //that's not Allegro entry, but needs to be preserved on the list
                return(new List <BankEntry>()
                {
                    entry
                });
            }
        }