import 'package:doctor_app_flutter/core/enum/view_state.dart';
import 'package:doctor_app_flutter/core/service/patient/profile/operation_report_servive.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/operation_report/create_update_operation_report_request_model.dart';
import 'package:doctor_app_flutter/core/model/operation_report/get_operation_details_request_modle.dart';
import 'package:doctor_app_flutter/core/model/operation_report/get_operation_details_response_modle.dart';
import 'package:doctor_app_flutter/core/model/operation_report/get_reservations_response_model.dart';

class OperationReportViewModel extends BaseViewModel {
  bool hasError = false;
  OperationReportService _operationReportService =
      locator<OperationReportService>();

  List<GetReservationsResponseModel> get reservationList =>
      _operationReportService.reservationList;

  List<GetOperationDetailsResponseModel> get operationDetailsList =>
      _operationReportService.operationDetailsList;

  Future getReservations(int patientId) async {
    hasError = false;
    setState(ViewState.Busy);
    await _operationReportService.getReservations(patientId: patientId, patientMRN: patientId);
    if (_operationReportService.hasError) {
      error = _operationReportService.error;
      setState(ViewState.ErrorLocal);
    } else {
      setState(ViewState.Idle);
    }
  }

  Future getOperationReportDetails(
      GetReservationsResponseModel reservation) async {
    hasError = false;
    setState(ViewState.Busy);
    GetOperationDetailsRequestModel getOperationReportRequestModel =
        GetOperationDetailsRequestModel(
            reservationNo: reservation.oTReservationID,
            patientID: reservation.patientID,
           );
    await _operationReportService.getOperationReportDetails(
        getOperationReportRequestModel: getOperationReportRequestModel);
    if (_operationReportService.hasError) {
      error = _operationReportService.error;
      setState(ViewState.ErrorLocal);
    } else {
      setState(ViewState.Idle);
    }
  }

  Future updateOperationReport(
      CreateUpdateOperationReportRequestModel
          createUpdateOperationReport) async {
    setState(ViewState.BusyLocal);
    await _operationReportService
        .updateOperationReport(createUpdateOperationReport);
    if (_operationReportService.hasError) {
      error = _operationReportService.error;
      setState(ViewState.ErrorLocal);
    } else
      setState(ViewState.Idle);
  }
}
