import 'package:logger/logger.dart';

import '../Entities/drift_database.dart';
import '../PlatformDependent/Web/local_notifications_web_stub.dart'
    if (dart.library.io) '../Controller/local_notifications.dart';
import '../Repositories/transaction_repository.dart';
import 'task.dart';

/// Zeigt Benachrichtigungen für nicht überprüfte Transaktionen an.
class ShowNotificationsTask extends Task {
  final TransactionRepository _transactionRepository = TransactionRepository();

  @override
  Future<bool> execute() async {
    final List<Transaction> transactions = await _transactionRepository.findBy(
      checked: false,
      dateTo: DateTime.now(),
    );

    if (transactions.isNotEmpty) {
      Logger().i('Showing notification for unchecked transactions...');

      await LocalNotifications().showTransactionsToCheckNotification(
        transactions,
      );
    }

    return Future.value(true);
  }
}
