import "../models/emprunt_response.dart"; import "../models/emprunt_item.dart"; import "api_client.dart"; /// Appels liƩs aux emprunts. class EmpruntService { EmpruntService._(); static const int posteEmpruntId = 1; static Future creerEmprunt({ required int materielId, required String commentaireDepart, required List> elements, }) async { final reponse = await ApiClient.post("/emprunts", { "materielId": materielId, "posteEmpruntId": posteEmpruntId, "modeIdentification": "MAIL_ENSUP", if (commentaireDepart.trim().isNotEmpty) "commentaireDepart": commentaireDepart.trim(), "elements": elements, }); final data = (reponse as Map)["data"] as Map; return EmpruntResponse.fromJson(data); } static Future> getMesEmprunts() async { final reponse = await ApiClient.get("/mes-emprunts"); final data = (reponse as Map)["data"] as List; return data.map((json) => EmpruntItem.fromJson(json as Map)).toList(); } static Future restituerEmprunt({ required int empruntId, required String commentaireRetour, required List> elements, }) async { final reponse = await ApiClient.post("/emprunts/$empruntId/restitution", { "modeIdentification": "MAIL_ENSUP", if (commentaireRetour.trim().isNotEmpty) "commentaireRetour": commentaireRetour.trim(), "elements": elements, }); final data = (reponse as Map)["data"] as Map; return EmpruntResponse.fromJson(data); } }