import 'package:doctor_app_flutter/core/enum/viewstate.dart';
import 'package:doctor_app_flutter/core/model/imei_details.dart';
import 'package:doctor_app_flutter/core/service/auth_service.dart';
import 'package:doctor_app_flutter/core/viewModel/base_view_model.dart';
import 'package:doctor_app_flutter/locator.dart';
import 'package:doctor_app_flutter/models/doctor/user_model.dart';
import 'package:doctor_app_flutter/util/helpers.dart';

class IMEIViewModel extends BaseViewModel {
  AuthService _authService = locator<AuthService>();
  List<GetIMEIDetailsModel> get imeiDetails => _authService.dashboardItemsList;
  get loginInfo => _authService.loginInfo;
  Future selectDeviceImei(imei) async {
    setState(ViewState.Busy);
    await _authService.selectDeviceImei(imei);
    if (_authService.hasError) {
      error = _authService.error;
      setState(ViewState.Error);
    } else
      setState(ViewState.Idle);
  }

  Future login(UserModel userInfo) async {
    setState(ViewState.Busy);
    await _authService.login(userInfo);
    if (_authService.hasError) {
      error = _authService.error;
      Helpers.showErrorToast(error);
      setState(ViewState.ErrorLocal);
    } else
      setState(ViewState.Idle);
  }
}
