import 'package:doctor_app_flutter/core/enum/view_state.dart';
import 'package:doctor_app_flutter/core/service/patient/referral_patient_service.dart';
import 'package:doctor_app_flutter/core/model/patient/my_referral/my_referral_patient_model.dart';

import '../../locator.dart';
import 'base_view_model.dart';

class ReferralPatientViewModel extends BaseViewModel {
  ReferralPatientService _referralPatientService =
      locator<ReferralPatientService>();

  List<MyReferralPatientModel> get listMyReferralPatientModel =>
      _referralPatientService.listMyReferralPatientModel;

  Future getMyReferralPatient() async {
    setState(ViewState.Busy);
    await _referralPatientService.getMyReferralPatient();
    if (_referralPatientService.hasError) {
      error = _referralPatientService.error;
      setState(ViewState.Error);
    } else
      setState(ViewState.Idle);
  }

  Future replay(
      String referredDoctorRemarks, MyReferralPatientModel model) async {
    setState(ViewState.BusyLocal);
    await _referralPatientService.replay(referredDoctorRemarks, model);
    if (_referralPatientService.hasError) {
      error = _referralPatientService.error;
      setState(ViewState.ErrorLocal);
    } else
      setState(ViewState.Idle);
  }
}
