import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/core/model/imei_details.dart';
import 'package:doctor_app_flutter/core/service/base/base_service.dart';
import 'package:doctor_app_flutter/models/doctor/user_model.dart';

class AuthService extends BaseService {
  List<GetIMEIDetailsModel> _imeiDetails = [];
  List<GetIMEIDetailsModel> get dashboardItemsList => _imeiDetails;
  Map<String, dynamic> _loginInfo = {};
  Map<String, dynamic> get loginInfo => _loginInfo;
  Future selectDeviceImei(imei) async {
    try {
      // dynamic localRes;
      await baseAppClient.post(SELECT_DEVICE_IMEI,
          onSuccess: (dynamic response, int statusCode) {
        _imeiDetails = [];
        response['List_DoctorDeviceDetails'].forEach((v) {
          _imeiDetails.add(GetIMEIDetailsModel.fromJson(v));
        });
      }, onFailure: (String error, int statusCode) {
        hasError = true;
        super.error = error;
      }, body: {"IMEI": imei, "TokenID": "@dm!n"});
      //return Future.value(localRes);
    } catch (error) {
      hasError = true;
      super.error = error;
    }
  }

  Future login(UserModel userInfo) async {
    hasError = false;
    _loginInfo = {};
    try {
      await baseAppClient.post(LOGIN_URL,
          onSuccess: (dynamic response, int statusCode) {
        _loginInfo = response;
      }, onFailure: (String error, int statusCode) {
        hasError = true;
        super.error = error;
      }, body: userInfo.toJson());
    } catch (error) {
      hasError = true;
      super.error = error;
    }

    //   await baseAppClient.post(SELECT_DEVICE_IMEI,
    //       onSuccess: (dynamic response, int statusCode) {
    //     _imeiDetails = [];
    //     response['List_DoctorDeviceDetails'].forEach((v) {
    //       _imeiDetails.add(GetIMEIDetailsModel.fromJson(v));
    //     });
    //   }, onFailure: (String error, int statusCode) {
    //     hasError = true;
    //     super.error = error;
    //   }, body: {});
    // } catch (error) {
    //   hasError = true;
    //   super.error = error;
    // }
  }
}
