import 'dart:convert'; import 'dart:io'; import 'package:flutter/material.dart'; import 'package:gen_service/Models/TransactionModels/BillDetailResponse.dart'; import 'package:gen_service/Models/TransactionModels/PaymentDetailResponse.dart'; import '../Models/AuthResponse.dart'; import '../Models/CommonResponse.dart'; import '../Models/DashboardResponse.dart'; import '../Models/TransactionModels/TransactionListResponse.dart'; import 'api_URLs.dart'; import 'api_post_request.dart'; import 'package:http/http.dart' as http show MultipartFile; class ApiCalling { /// Fetch gen service contact by mobile number static Future fetchRentalMobileApi( String mob, ) async { debugPrint("############################### Api calling "); try { Map data = { "mob": mob, }; final res = await post(data, fetchMobileUrl, {}); if (res != null) { return FetchMobileResponse.fromJson(jsonDecode(res.body)); } else { debugPrint("Null Response"); return null; } } catch (e) { debugPrint("❌ API Error: $e"); return null; } } static Future fetchMobileOtpApi( String mob, String otp, deviceDetails ) async { debugPrint("############################### Api fetch otpcalling "); try { Map data = { "mob": mob, "otp": otp, "device_details": deviceDetails.toString(), }; print(data); final res = await post(data, fetchOtpUrl, {}); if (res != null) { print(res.body); return FetchOTPResponse.fromJson(jsonDecode(res.body)); } else { debugPrint("Null Response"); return null; } } catch (e) { debugPrint("❌ API Error: $e"); return null; } } static Future logoutApi( String accId, String sessionId, ) async { debugPrint("############################### Api calling "); try { Map data = { "acc_id": accId, "session_id": sessionId, }; final res = await post(data, logoutUrl, {}); if (res != null) { return CommonResponse.fromJson(jsonDecode(res.body)); } else { debugPrint("Null Response"); return null; } } catch (e) { debugPrint("❌ Logout API Error: $e"); return null; } } /// fetch Dashboard Api static Future fetchDashboardApi( String accId, String sessionId, ) async { debugPrint("############################### Api calling "); try { Map data = { "acc_id": accId, "session_id": sessionId, }; final res = await post(data, dashboardUrl, {}); if (res != null) { return DashboardResponse.fromJson(jsonDecode(res.body)); } else { debugPrint("Null Response"); return null; } } catch (e) { debugPrint("❌ Dashboard API Error: $e"); return null; } } /// fetch Dashboard Api static Future fetchTransactionListApi( String accId, String sessionId, ) async { debugPrint("###############################Transaction Api calling "); try { Map data = { "acc_id": accId, "session_id": sessionId, }; final res = await post(data, transactionsUrl, {}); debugPrint("Transaction response: ${res?.body}"); if (res != null) { return TransactionListResponse.fromJson(jsonDecode(res.body)); } else { debugPrint("Null Response"); return null; } } catch (e) { debugPrint("❌ Transaction API Error: $e"); return null; } } /// fetch Payment Details Api static Future fetchPaymentDetailApi( String accId, String sessionId, String billId ) async { debugPrint("###############################Transaction Api calling "); try { Map data = { "acc_id": accId, "session_id": sessionId, "bill_id": billId, }; final res = await post(data, paymentDetailUrl, {}); debugPrint("Transaction response: ${res?.body}"); if (res != null) { return PaymentDetailResponse.fromJson(jsonDecode(res.body)); } else { debugPrint("Null Response"); return null; } } catch (e) { debugPrint("❌ Payment Details API Error: $e"); return null; } } /// fetch Bill Details Api static Future fetchBillDetailApi( String accId, String sessionId, String billId ) async { debugPrint("###############################Transaction Api calling "); try { Map data = { "acc_id": accId, "session_id": sessionId, "bill_id": billId, }; final res = await post(data, billDetailUrl, {}); debugPrint("Transaction response: ${res?.body}"); if (res != null) { return BillDetailResponse.fromJson(jsonDecode(res.body)); } else { debugPrint("Null Response"); return null; } } catch (e) { debugPrint("❌ Bill Detail API Error: $e"); return null; } } // // /// pay_amount // static Future payAmountApi( // String sessionId, // String empId, // String ammount, // String refType, // String refId, // ) async { // try { // Map data = { // "session_id": sessionId, // "acc_id": empId, // "amount": ammount, // "ref_type": refType, // "ref_id": refId, // }; // // final res = await post(data, payAmountUrl, {}); // debugPrint("PayAmount Response ${res?.body}"); // // if (res != null) { // return PayAmountResponse.fromJson(jsonDecode(res.body)); // } else { // debugPrint("Null Response"); // return null; // } // } catch (e) { // debugPrint("❌ API Error (payAmountApi): $e"); // return null; // } // } // }