import "api_client.dart"; /// Appels API du tableau responsable matériel. class ResponsableService { ResponsableService._(); static Future> dashboard() async { final reponse = await ApiClient.get("/responsable/dashboard"); return Map.from(reponse["data"] as Map); } static Future>> emprunts() => _liste("/responsable/emprunts"); static Future>> materiels() => _liste("/responsable/materiels"); static Future>> anomalies() => _liste("/responsable/anomalies"); static Future>> notifications() => _liste("/responsable/notifications"); static Future>> historique() => _liste("/responsable/historique"); static Future exporterHistorique() => ApiClient.getFile( "/responsable/historique/export.csv", fallbackFileName: "historique-responsable.csv", ); static Future marquerNotificationsLues() async { final reponse = await ApiClient.patch( "/responsable/notifications/lu-toutes", {}, ); final data = Map.from(reponse["data"] as Map); return data["count"] as int; } static Future> changerStatutAnomalie( int id, String statut, ) async { final reponse = await ApiClient.patch("/responsable/anomalies/$id/statut", { "statut": statut, "observation": "Traitement depuis l'interface responsable", }); return Map.from(reponse["data"] as Map); } static Future>> _liste(String chemin) async { final reponse = await ApiClient.get(chemin); final data = reponse["data"] as List; return data.map((item) => Map.from(item as Map)).toList(); } }