import 'package:doctor_app_flutter/config/shared_pref_kay.dart';
import 'package:doctor_app_flutter/core/enum/viewstate.dart';
import 'package:doctor_app_flutter/models/doctor/doctor_profile_model.dart';
import 'package:doctor_app_flutter/util/dr_app_shared_pref.dart';
import 'package:flutter/material.dart';

class BaseViewModel extends ChangeNotifier {
  DrAppSharedPreferances sharedPref = new DrAppSharedPreferances();
  DoctorProfileModel doctorProfile;

  ViewState _state = ViewState.Idle;
  bool isInternetConnection = true;

  ViewState get state => _state;

  String error = "";

  //TODO add the user login model when we need it

  void setState(ViewState viewState) {
    _state = viewState;
    notifyListeners();
  }

  Future<DoctorProfileModel> getDoctorProfile() async {
    if (doctorProfile == null) {
      Map profile = await sharedPref.getObj(DOCTOR_PROFILE);
      if (profile != null) {
        doctorProfile = DoctorProfileModel.fromJson(profile);
        if (doctorProfile != null) {
          return doctorProfile;
        }
      }
      return null;
    } else {
      return doctorProfile;
    }
  }
}
