import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../domain/entities/contribution.dart';
import '../../domain/usecases/contribution/get_user_contribution.dart';
import '../../core/di/injection.dart';

final getUserContributionUseCaseProvider = Provider<GetUserContribution>((ref) {
  return getIt<GetUserContribution>();
});

final contributionProvider = FutureProvider.family<Contribution?, String>(
  (ref, accountSequence) async {
    final useCase = ref.watch(getUserContributionUseCaseProvider);
    final result = await useCase(accountSequence);
    return result.fold(
      (failure) => throw Exception(failure.message),
      (contribution) => contribution,
    );
  },
);
