import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:em2rp/services/equipment_status_calculator.dart'; import 'package:em2rp/services/api_service.dart'; /// Service étendu pour gérer les 4 étapes : Préparation, Chargement, Déchargement, Retour class EventPreparationServiceExtended { final ApiService _apiService = apiService; // === CHARGEMENT (LOADING) === /// Valider un équipement individuel pour le chargement Future validateEquipmentLoading(String eventId, String equipmentId) async { try { await _apiService.call('validateEquipmentLoading', { 'eventId': eventId, 'equipmentId': equipmentId, }); } catch (e) { print('Error validating equipment loading: $e'); rethrow; } } /// Valider tous les équipements pour le chargement Future validateAllLoading(String eventId) async { try { await _apiService.call('validateAllLoading', { 'eventId': eventId, }); // Invalider le cache des statuts d'équipement EquipmentStatusCalculator.invalidateGlobalCache(); } catch (e) { print('Error validating all loading: $e'); rethrow; } } // === DÉCHARGEMENT (UNLOADING) === /// Valider un équipement individuel pour le déchargement Future validateEquipmentUnloading(String eventId, String equipmentId) async { try { await _apiService.call('validateEquipmentUnloading', { 'eventId': eventId, 'equipmentId': equipmentId, }); } catch (e) { print('Error validating equipment unloading: $e'); rethrow; } } /// Valider tous les équipements pour le déchargement Future validateAllUnloading(String eventId) async { try { await _apiService.call('validateAllUnloading', { 'eventId': eventId, }); // Invalider le cache des statuts d'équipement EquipmentStatusCalculator.invalidateGlobalCache(); } catch (e) { print('Error validating all unloading: $e'); rethrow; } } // === PRÉPARATION + CHARGEMENT === /// Valider préparation ET chargement en même temps Future validateAllPreparationAndLoading(String eventId) async { try { // Note: On pourrait créer une fonction cloud dédiée pour ça, // mais pour l'instant on appelle les deux séquentiellement await _apiService.call('validateAllPreparation', {'eventId': eventId}); await _apiService.call('validateAllLoading', {'eventId': eventId}); // Invalider le cache EquipmentStatusCalculator.invalidateGlobalCache(); } catch (e) { print('Error validating all preparation and loading: $e'); rethrow; } } // === DÉCHARGEMENT + RETOUR === /// Valider déchargement ET retour en même temps Future validateAllUnloadingAndReturn( String eventId, Map? returnedQuantities, ) async { try { // Note: On pourrait créer une fonction cloud dédiée pour ça, // mais pour l'instant on appelle les deux séquentiellement await _apiService.call('validateAllUnloading', {'eventId': eventId}); await _apiService.call('validateAllReturn', { 'eventId': eventId, if (returnedQuantities != null) 'returnedQuantities': returnedQuantities, }); // Invalider le cache EquipmentStatusCalculator.invalidateGlobalCache(); } catch (e) { print('Error validating all unloading and return: $e'); rethrow; } } }