import 'package:doctor_app_flutter/core/enum/viewstate.dart';
import 'package:doctor_app_flutter/core/service/referred_patient_service.dart';
import 'package:doctor_app_flutter/models/patient/my_referral/my_referred_patient_model.dart';

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

class ReferredPatientViewModel extends BaseViewModel {
  ReferredPatientService _referralPatientService = locator<ReferredPatientService>();

  List<MyReferredPatientModel> get listMyReferredPatientModel => _referralPatientService.listMyReferredPatientModel;

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

  Future verify(MyReferredPatientModel model) async {
    setState(ViewState.BusyLocal);
    await _referralPatientService.verify(model);
    if (_referralPatientService.hasError) {
      error = _referralPatientService.error;
      setState(ViewState.ErrorLocal);
    } else
      setState(ViewState.Idle);
  }
}
