import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../../../core/api/api_providers.dart'; import '../../../core/api/guarded_api_call.dart'; import '../../auth/data/auth_providers.dart'; import '../domain/inventory_item.dart'; import '../domain/inventory_consumption.dart'; import 'inventory_repository.dart'; final inventoryRepositoryProvider = Provider((ref) { return InventoryRepository(ref.watch(apiClientProvider)); }); final inventoryProvider = FutureProvider>((ref) async { final token = await ref.watch(authStateProvider.future); return guardedApiCall( ref, () => ref.read(inventoryRepositoryProvider).fetchInventory(token: token), ); }); final inventoryDetailProvider = FutureProvider.family((ref, id) async { final token = await ref.watch(authStateProvider.future); return guardedApiCall( ref, () => ref.read(inventoryRepositoryProvider).fetchInventoryItem(id, token: token), ); }); final consumptionHistoryProvider = FutureProvider.family, int>((ref, id) async { final token = await ref.watch(authStateProvider.future); return guardedApiCall( ref, () => ref .read(inventoryRepositoryProvider) .fetchConsumptionHistory(id, token: token), ); });