import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart';
import 'package:diplomaticquarterapp/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;

  String error = "";

  AuthenticatedUser user;
  AppSharedPreferences sharedPref = AppSharedPreferences();

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

  BaseViewModel() {
    _getUser();
  }

  _getUser() async {
    var userData = await sharedPref.getObject(USER_PROFILE);
    if (userData != null) user = AuthenticatedUser.fromJson(userData);
    notifyListeners();
  }
}
