import 'package:doctor_app_flutter/core/enum/view_state.dart';
import 'package:doctor_app_flutter/core/service/patient/profile/discharge_summary_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/discharge_summary/GetDischargeSummaryReqModel.dart';
import 'package:doctor_app_flutter/core/model/discharge_summary/GetDischargeSummaryResModel.dart';

class DischargeSummaryViewModel extends BaseViewModel {
  bool hasError = false;
  DischargeSummaryService _dischargeSummaryService =
      locator<DischargeSummaryService>();

  List<GetDischargeSummaryResModel> get pendingDischargeSummaryList =>
      _dischargeSummaryService.pendingDischargeSummaryList;

  List<GetDischargeSummaryResModel> get allDisChargeSummaryList =>
      _dischargeSummaryService.allDischargeSummaryList;

  Future getPendingDischargeSummary({
    required int patientId,
    required int admissionNo, required int? clinicId,
  }) async {

    print("the clinic id is $clinicId");
    GetDischargeSummaryReqModel getDischargeSummaryReqModel =
        GetDischargeSummaryReqModel(
            admissionNo: admissionNo, patientID: patientId, clinicId: clinicId , doctorId:null);
    hasError = false;
    setState(ViewState.Busy);
    await _dischargeSummaryService.getPendingDischargeSummary(
        getDischargeSummaryReqModel: getDischargeSummaryReqModel);
    if (_dischargeSummaryService.hasError) {
      error = _dischargeSummaryService.error!;
      setState(ViewState.ErrorLocal);
    } else {
      setState(ViewState.Idle);
    }
  }

  Future getAllDischargeSummary({
    required int patientId,
    required int admissionNo,
  }) async {
    GetDischargeSummaryReqModel getDischargeSummaryReqModel =
        GetDischargeSummaryReqModel(
            admissionNo: admissionNo, patientID: patientId);
    hasError = false;
    setState(ViewState.Busy);
    await _dischargeSummaryService.getAllDischargeSummary(
        getDischargeSummaryReqModel: getDischargeSummaryReqModel);
    if (_dischargeSummaryService.hasError) {
      error = _dischargeSummaryService.error;
      setState(ViewState.ErrorLocal);
    } else {
      setState(ViewState.Idle);
    }
  }
}
