import 'package:doctor_app_flutter/core/enum/view_state.dart';
import 'package:doctor_app_flutter/core/service/pending_order_service.dart';
import 'package:doctor_app_flutter/core/viewModel/base_view_model.dart';
import 'package:doctor_app_flutter/locator.dart';
import 'package:doctor_app_flutter/core/model/admisson_orders/admission_orders_model.dart';
import 'package:doctor_app_flutter/core/model/pending_orders/pending_orders_model.dart';

class PendingOrdersViewModel extends BaseViewModel {
  bool hasError = false;
  PendingOrderService _pendingOrderService = locator<PendingOrderService>();

  List<PendingOrderModel> get pendingOrdersList =>
      _pendingOrderService.pendingOrderList;

  List<AdmissionOrdersModel> get admissionOrderList =>
      _pendingOrderService.admissionOrderList;

  Future getPendingOrders(
      {required int patientId,
      required int admissionNo,
      required bool isVidaPlus}) async {
    hasError = false;
    setState(ViewState.Busy);
    if (isVidaPlus) {
      await _pendingOrderService.getPendingOrdersForVidaPlus(
          patientId: patientId, admissionNo: admissionNo);
    } else {
      await _pendingOrderService.getPendingOrders(
          patientId: patientId, admissionNo: admissionNo);
    }
    if (_pendingOrderService.hasError) {
      error = _pendingOrderService.error;
      setState(ViewState.ErrorLocal);
    } else {
      setState(ViewState.Idle);
    }
  }

  Future getAdmissionOrders({required int patientId, required int admissionNo, int? admissionRequestNo}) async {
    hasError = false;
    setState(ViewState.Busy);
    await _pendingOrderService.getAdmissionOrders(
        patientId: patientId, admissionNo: admissionNo, admissionRequestNo: admissionRequestNo);
    if (_pendingOrderService.hasError) {
      error = _pendingOrderService.error;
      setState(ViewState.ErrorLocal);
    } else {
      setState(ViewState.Idle);
    }
  }
}
