import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/core/model/admisson_orders/admission_orders_model.dart';
import 'package:doctor_app_flutter/core/model/admisson_orders/admission_orders_request_model.dart';
import 'package:doctor_app_flutter/core/model/pending_orders/pending_order_request_model.dart';
import 'package:doctor_app_flutter/core/model/pending_orders/pending_orders_model.dart';
import 'package:doctor_app_flutter/core/service/base/base_service.dart';

class PendingOrderService extends BaseService {
  List<PendingOrderModel> _pendingOrderList = [];

  List<PendingOrderModel> get pendingOrderList => _pendingOrderList;

  List<AdmissionOrdersModel> _admissionOrderList = [];

  List<AdmissionOrdersModel> get admissionOrderList => _admissionOrderList;

  Future getPendingOrders({PendingOrderRequestModel? pendingOrderRequestModel, int? patientId, int? admissionNo}) async {
    pendingOrderRequestModel = PendingOrderRequestModel(
      patientID: patientId,
      admissionNo: admissionNo,
      patientTypeID: 1,
      patientType: 1,
    );

    hasError = false;
    await baseAppClient.post(GET_PENDING_ORDERS, onSuccess: (dynamic response, int statusCode) {
      print("Success");
      _pendingOrderList.clear();
      response['List_PendingOrders'].forEach(
        (v) {
          _pendingOrderList.add(PendingOrderModel.fromJson(v));
        },
      );
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: pendingOrderRequestModel.toJson());
  }

  Future getPendingOrdersForVidaPlus({PendingOrderRequestModel? pendingOrderRequestModel, int? patientId, int? admissionNo,}) async {
    pendingOrderRequestModel = PendingOrderRequestModel(
      patientID: patientId,
      admissionNo: admissionNo,
      patientTypeID: 1,
      patientType: 1,
    );

    hasError = false;
    await baseAppClient.post(GET_PENDING_ORDERS_VIDA_PLUS, onSuccess: (dynamic response, int statusCode) {
      print("Success");
      _pendingOrderList.clear();
      response['List_DoctorProgressNote'].forEach(
        (v) {
          _pendingOrderList.add(PendingOrderModel.fromJson(v));
        },
      );
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: pendingOrderRequestModel.toJson());
  }

  Future getAdmissionOrders({AdmissionOrdersRequestModel? admissionOrdersRequestModel, int? patientId, int? admissionNo, int? admissionRequestNo}) async {
    admissionOrdersRequestModel = AdmissionOrdersRequestModel(
      patientID: patientId,
      admissionNo: admissionNo,
      patientTypeID: 1,
      patientType: 1,
      admissionRequestNo: admissionRequestNo
    );
    admissionOrderList.clear();
    hasError = false;
    await baseAppClient.post(GET_ADMISSION_ORDERS, onSuccess: (dynamic response, int statusCode) {
      print("Success");
      response['List_AdmissionOrders'].forEach(
        (v) {
          _admissionOrderList.add(AdmissionOrdersModel.fromJson(v));
        },
      );
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: admissionOrdersRequestModel.toJson());
  }
}
