import 'package:hmg_patient_app/config/config.dart';
import 'package:hmg_patient_app/core/service/base_service.dart';
import 'package:hmg_patient_app/models/anicllary-orders/ancillary_order_list_model.dart';
import 'package:hmg_patient_app/models/anicllary-orders/ancillary_order_proc_model.dart';

class AncillaryOrdersService extends BaseService {
  List<AncillaryOrdersListModel> _ancillaryLists =[];

  List<AncillaryOrdersListModel> get ancillaryLists => _ancillaryLists;
  List<AncillaryOrdersListProcListModel> _ancillaryProcLists =[];

  List<AncillaryOrdersListProcListModel> get ancillaryProcLists => _ancillaryProcLists;

  String _insuranceCompanyName = "";

  String get insuranceCompanyName => _insuranceCompanyName;
  String _insurancePolicyNumber = "";

  String get insurancePolicyNumber => _insurancePolicyNumber;

  Future getOrders() async {
    Map<String, dynamic> body = Map();

    hasError = false;

    await baseAppClient.post(GET_ANCILLARY_ORDERS, onSuccess: (dynamic response, int statusCode) {
      _ancillaryLists = [];
      response['AncillaryOrderList'].forEach((item) {
        ancillaryLists.add(AncillaryOrdersListModel.fromJson(item));
      });
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
  }

  Future<Map> getOrdersMyAppo() async {
    Map<String, dynamic> body = Map();

    hasError = false;

    dynamic localRes;

    await baseAppClient.post(GET_ANCILLARY_ORDERS, onSuccess: (dynamic response, int statusCode) {
      _ancillaryLists = [];
      localRes = response;
      response['AncillaryOrderList'].forEach((item) {
        ancillaryLists.add(AncillaryOrdersListModel.fromJson(item));
      });
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
    return Future.value(localRes);
  }

  Future<Map> getOrdersDetails(appointmentNo, orderNo, projectID) async {
    Map<String, dynamic> body = Map();
    body['AppointmentNo_Vida'] = appointmentNo;
    body['OrderNo'] = orderNo;
    body['ProjectID'] = projectID;
    hasError = false;

    dynamic localRes;

    await baseAppClient.post(GET_ANCILLARY_ORDERS_DETAILS, onSuccess: (dynamic response, int statusCode) {
      localRes = response;
      _ancillaryProcLists = [];
      response['AncillaryOrderProcList'].forEach((item) {
        ancillaryProcLists.add(AncillaryOrdersListProcListModel.fromJson(item));
      });
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
    return Future.value(localRes);
  }
}
