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

class AncillaryOrdersService extends BaseService {
  List<AncillaryOrdersListModel> _ancillaryLists = List();
  List<AncillaryOrdersListModel> get ancillaryLists => _ancillaryLists;
  List<AncillaryOrdersListProcListModel> _ancillaryProcLists = List();
  List<AncillaryOrdersListProcListModel> get ancillaryProcLists =>
      _ancillaryProcLists;

  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 getOrdersDetails(appointmentNo, orderNo) async {
    Map<String, dynamic> body = Map();

    hasError = false;

    await baseAppClient.post(GET_ANCILLARY_ORDERS_DETAILS,
        onSuccess: (dynamic response, int statusCode) {
      _ancillaryProcLists = [];
      response['AncillaryOrderProcList'] = [
        {
          "AncillaryOrderProcList": [
            {
              "ApprovalLineItemNo": 0,
              "ApprovalNo": 0,
              "ApprovalStatus": "",
              "ApprovalStatusID": 0,
              "CompanyShare": 501.3,
              "CompanyShareWithTax": 576.5,
              "CompanyTaxAmount": 75.19,
              "DiscountAmount": 55.7,
              "DiscountCategory": 1,
              "DiscountType": "P",
              "DiscountTypeValue": 10,
              "IsApprovalCreated": false,
              "IsApprovalRequired": false,
              "IsCovered": false,
              "OrderDate": "/Date(1601758800000+0300)/",
              "OrderLineItemNo": 1,
              "OrderNo": 2020000001,
              "PartnerID": 0,
              "PartnerShare": 0,
              "PartnerShareType": "P",
              "PatientShare": 0,
              "PatientShareWithTax": 0,
              "PatientTaxAmount": 0,
              "ProcPrice": 557,
              "ProcedureCategoryID": 2,
              "ProcedureCategoryName": "LABORATORY",
              "ProcedureID": "02013001",
              "ProcedureName": "11-DESOXYCORTISOL (COMPOUND S) - S.O",
              "TaxAmount": 75.19,
              "TaxPct": 15
            },
            {
              "ApprovalLineItemNo": 0,
              "ApprovalNo": 0,
              "ApprovalStatus": "",
              "ApprovalStatusID": 0,
              "CompanyShare": 90,
              "CompanyShareWithTax": 103.5,
              "CompanyTaxAmount": 13.5,
              "DiscountAmount": 10,
              "DiscountCategory": 1,
              "DiscountType": "P",
              "DiscountTypeValue": 10,
              "IsApprovalCreated": false,
              "IsApprovalRequired": true,
              "IsCovered": false,
              "OrderDate": "/Date(1601758800000+0300)/",
              "OrderLineItemNo": 4,
              "OrderNo": 2020000001,
              "PartnerID": 0,
              "PartnerShare": 0,
              "PartnerShareType": "P",
              "PatientShare": 0,
              "PatientShareWithTax": 0,
              "PatientTaxAmount": 0,
              "ProcPrice": 100,
              "ProcedureCategoryID": 2,
              "ProcedureCategoryName": "LABORATORY",
              "ProcedureID": "02014011",
              "ProcedureName": "CBC (COMPLETE BLOOD COUNT PROFILE)",
              "TaxAmount": 13.5,
              "TaxPct": 15
            },
            {
              "ApprovalLineItemNo": 0,
              "ApprovalNo": 0,
              "ApprovalStatus": "",
              "ApprovalStatusID": 0,
              "CompanyShare": 347.76,
              "CompanyShareWithTax": 399.92,
              "CompanyTaxAmount": 52.16,
              "DiscountAmount": 38.64,
              "DiscountCategory": 1,
              "DiscountType": "P",
              "DiscountTypeValue": 10,
              "IsApprovalCreated": false,
              "IsApprovalRequired": false,
              "IsCovered": false,
              "OrderDate": "/Date(1601758800000+0300)/",
              "OrderLineItemNo": 3,
              "OrderNo": 2020000001,
              "PartnerID": 0,
              "PartnerShare": 0,
              "PartnerShareType": "P",
              "PatientShare": 0,
              "PatientShareWithTax": 0,
              "PatientTaxAmount": 0,
              "ProcPrice": 386.4,
              "ProcedureCategoryID": 2,
              "ProcedureCategoryName": "LABORATORY",
              "ProcedureID": "02019302",
              "ProcedureName": "21-HYDROXYLASE ABS - S.O",
              "TaxAmount": 52.16,
              "TaxPct": 15
            },
            {
              "ApprovalLineItemNo": 0,
              "ApprovalNo": 0,
              "ApprovalStatus": "",
              "ApprovalStatusID": 0,
              "CompanyShare": 1323,
              "CompanyShareWithTax": 1521.45,
              "CompanyTaxAmount": 198.45,
              "DiscountAmount": 147,
              "DiscountCategory": 1,
              "DiscountType": "P",
              "DiscountTypeValue": 10,
              "IsApprovalCreated": false,
              "IsApprovalRequired": true,
              "IsCovered": false,
              "OrderDate": "/Date(1601758800000+0300)/",
              "OrderLineItemNo": 5,
              "OrderNo": 2020000001,
              "PartnerID": 0,
              "PartnerShare": 0,
              "PartnerShareType": "P",
              "PatientShare": 0,
              "PatientShareWithTax": 0,
              "PatientTaxAmount": 0,
              "ProcPrice": 1470,
              "ProcedureCategoryID": 3,
              "ProcedureCategoryName": "RADIOLOGY",
              "ProcedureID": "03033065",
              "ProcedureName": "CT SCAN - ABDOMEN (WITH CONTRAST)",
              "TaxAmount": 198.45,
              "TaxPct": 15
            }
          ],
          "AppointmentDate": "/Date(1601499600000+0300)/",
          "AppointmentNo": 2016053756,
          "ClinicID": 1,
          "ClinicName": "INTERNAL MEDICINE CLINIC",
          "CompanyID": 0,
          "CompanyName": "Blood Donation Investigation",
          "DoctorID": 1485,
          "DoctorName": "ANAS ABDULLAH",
          "ErrCode": null,
          "GroupID": 2,
          "InsurancePolicyNo": "45976500",
          "Message": "Success",
          "PatientCardID": "232332323",
          "PatientID": 3072055,
          "PatientName": "MAYA KHALED SADDIQ",
          "PatientType": 1,
          "PolicyID": 2,
          "PolicyName": "Test",
          "ProjectID": 15,
          "SetupID": "010266",
          "StatusCode": 1,
          "SubCategoryID": 2,
          "SubPolicyNo": "234234"
        }
      ];

      response['AncillaryOrderProcList'].forEach((item) {
        ancillaryProcLists.add(AncillaryOrdersListProcListModel.fromJson(item));
      });
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
  }
}
