LCOV - code coverage report
Current view: top level - lib/_classes/integration/enablebanking - enablebanking_importer.dart Coverage Total Hit
Test: lcov.info Lines: 0.0 % 20 0
Test Date: 2026-12-05 10:54:13 Functions: - 0 0

            Line data    Source code
       1              : // Copyright 2026 The terCAD team. All rights reserved.
       2              : // Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file.
       3              : 
       4              : import 'package:app_finance/_classes/integration/enablebanking/enablebanking_client.dart';
       5              : import 'package:app_finance/_classes/integration/integration_record.dart';
       6              : import 'package:app_finance/_classes/math/budget_prediction.dart';
       7              : import 'package:app_finance/_classes/structure/interface_app_data.dart';
       8              : import 'package:uuid/uuid.dart';
       9              : 
      10              : class EnableBankingImporter {
      11              :   final bool Function(String uuid) exists;
      12              :   final void Function(InterfaceAppData item, String uuid) add;
      13              : 
      14            0 :   const EnableBankingImporter({required this.exists, required this.add});
      15              : 
      16            0 :   IntegrationImportResult run({
      17              :     required String accountKey,
      18              :     required List<EnableBankingTransaction> transactions,
      19              :     required String account,
      20              :     required String category,
      21              :     BudgetPrediction? prediction,
      22              :   }) {
      23              :     var added = 0;
      24              :     var skipped = 0;
      25              :     var pending = 0;
      26            0 :     final occurrences = <String, int>{};
      27            0 :     for (final transaction in transactions) {
      28            0 :       final date = transaction.date;
      29            0 :       if (!transaction.isBooked || date == null) {
      30            0 :         pending++;
      31              :         continue;
      32              :       }
      33            0 :       final reference = transaction.reference ??
      34            0 :           [date.toIso8601String().substring(0, 10), transaction.amount, transaction.currency, transaction.title]
      35            0 :               .join('|');
      36            0 :       final index = occurrences.update(reference, (value) => value + 1, ifAbsent: () => 0);
      37            0 :       final uuid = const Uuid().v5(Namespace.url.value, 'enablebanking:$accountKey:$reference#$index');
      38            0 :       if (exists(uuid)) {
      39            0 :         skipped++;
      40              :         continue;
      41              :       }
      42            0 :       add(
      43            0 :         IntegrationRecord.toAppData(
      44            0 :           amount: transaction.amount,
      45            0 :           currency: transaction.currency,
      46              :           date: date,
      47            0 :           title: transaction.title,
      48              :           account: account,
      49              :           category: category,
      50              :           prediction: prediction,
      51              :         ),
      52              :         uuid,
      53              :       );
      54            0 :       added++;
      55              :     }
      56              :     return (added: added, skipped: skipped, pending: pending);
      57              :   }
      58              : }
        

Generated by: LCOV version 2.0-1