import 'package:diplomaticquarterapp/config/config.dart';
import 'package:diplomaticquarterapp/core/enum/OrderService.dart';
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/HomeHealthCare/HHC_get_all_services_request_modle.dart';
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/HomeHealthCare/HHC_get_all_services_response_model.dart';
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/HomeHealthCare/get_hHC_all_pres_orders_request_model.dart';
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/HomeHealthCare/get_hhc_all_pres_orders_response_model.dart';
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/HomeHealthCare/get_order_detail_by_order_iD_request_model.dart';
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/HomeHealthCare/get_order_detail_by_order_iD_response_model.dart';
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/HomeHealthCare/patient_er_insert_pres_order_request_model.dart';
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/HomeHealthCare/update_pres_oreder_request_model.dart';
import 'package:diplomaticquarterapp/core/service/AlHabibMedicalService/customer_addresses_service.dart';
import 'package:diplomaticquarterapp/core/viewModels/AlHabibMedicalService/add_new_address_Request_Model.dart';

import '../base_service.dart';

class HomeHealthCareService extends BaseService {
  List<HHCGetAllServicesResponseModel> hhcAllServicesList = List();
  List<GetHHCAllPresOrdersResponseModel> hhcAllPresOrdersList = List();

  List<GetOrderDetailByOrderIDResponseModel> hhcAllOrderDetail = List();
  List<AddressInfo> addressesList = List();

  bool isOrderUpdated;
  CustomerInfo customerInfo;
  Future getHHCAllServices(
      HHCGetAllServicesRequestModel hHCGetAllServicesRequestModel) async {
    hasError = false;
    await baseAppClient.post(HHC_GET_ALL_SERVICES,
        onSuccess: (dynamic response, int statusCode) {
      hhcAllServicesList.clear();
      response['PatientER_HHC_GetAllServicesList'].forEach((data) {
        hhcAllServicesList.add(HHCGetAllServicesResponseModel.fromJson(data));
      });
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: hHCGetAllServicesRequestModel.toJson());
  }

  Future getHHCAllPresOrders() async {
    GetHHCAllPresOrdersRequestModel getHHCAllPresOrdersRequestModel =
        GetHHCAllPresOrdersRequestModel();
    hasError = false;
    await baseAppClient.post(GET_PATIENT_ALL_PRES_ORD,
        onSuccess: (dynamic response, int statusCode) {
      hhcAllPresOrdersList.clear();
      response['PatientER_GetPatientAllPresOrdersList'].forEach((data) {
        if (data['ServiceID'] == OrderService.HOME_HEALTH_CARE.getIdOrderService())
          hhcAllPresOrdersList
              .add(GetHHCAllPresOrdersResponseModel.fromJson(data));
      });
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: getHHCAllPresOrdersRequestModel.toJson());
  }

  Future getOrderDetailByOrderID(int presOrderID) async {
    hasError = false;
    Map<String, dynamic> body = Map();
    body['PresOrderID'] = presOrderID;
    body['isDentalAllowedBackend'] = false;
    await baseAppClient.post(GET_ORDER_DETAIL_BY_ID,
        onSuccess: (dynamic response, int statusCode) {
      hhcAllOrderDetail.clear();
      response['PatientER_HHC_GetTransactionsForOrderList'].forEach((data) {
        hhcAllOrderDetail
            .add(GetOrderDetailByOrderIDResponseModel.fromJson(data));
      });
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
  }

  Future updateHHCPresOrder(UpdatePresOrderRequestModel updatePresOrderRequestModel) async {
    hasError = false;
    await baseAppClient.post(PATIENT_ER_UPDATE_PRES_ORDER,
        onSuccess: (dynamic response, int statusCode) {
      isOrderUpdated = true;
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: updatePresOrderRequestModel.toJson());
  }

  Future insertPresPresOrder({PatientERInsertPresOrderRequestModel order}) async {
    hasError = false;
    await baseAppClient.post(INSERT_ER_INERT_PRES_ORDER,
        onSuccess: (dynamic response, int statusCode) {

    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: order.toJson());
  }
}


