import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:sysfarma_mobile/src/core/network/api_client.dart'; /// Pago recibido tal como lo devuelve el backend (getApiRowResource). class ReceivedPaymentRow { const ReceivedPaymentRow({ required this.id, required this.provider, required this.amount, required this.status, this.senderName, this.postedAt, }); final int id; final String provider; final double amount; final String status; final String? senderName; final String? postedAt; factory ReceivedPaymentRow.fromMap(Map map) { return ReceivedPaymentRow( id: (map['id'] as num).toInt(), provider: map['provider']?.toString() ?? 'YAPE', amount: (map['amount'] as num?)?.toDouble() ?? 0, status: map['status']?.toString() ?? 'pending', senderName: map['sender_name']?.toString(), postedAt: map['posted_at']?.toString(), ); } } /// Lista de pagos pendientes de la bandeja. autoDispose + family por estado /// para poder recargar con ref.invalidate tras reclamar/descartar. final yapeInboxProvider = FutureProvider.autoDispose .family, String>((ref, status) async { final api = ref.watch(apiClientProvider); final response = await api.yapeInbox(status: status, perPage: 50); if (!response.success) { throw Exception(response.message ?? 'No se pudo cargar la bandeja.'); } return (response.data ?? []) .map((row) => ReceivedPaymentRow.fromMap(row)) .toList(); });