import 'package:driverapp/config/shared_pref_kay.dart';
import 'package:driverapp/core/enum/viewstate.dart';
import 'package:driverapp/core/model/authentication/authenticated_user.dart';
import 'package:driverapp/uitl/app_shared_preferences.dart';
import 'package:flutter/material.dart';

class BaseViewModel extends ChangeNotifier {
  ViewState _state = ViewState.Idle;
  bool isInternetConnection = true;

  ViewState get state => _state;
  AuthenticatedUser user;
  String error = "";
  AppSharedPreferences sharedPref = AppSharedPreferences();

  BaseViewModel() {
    getUser();
  }

  getUser() async {
    var userProfile = await sharedPref.getObject(USER_PROFILE);
    if (userProfile != null) {
      user =
          AuthenticatedUser.fromJson(await sharedPref.getObject(USER_PROFILE));
    }
  }

  //TODO load user details from SP

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