import 'package:doctor_app_flutter/client/base_app_client.dart';
import 'package:doctor_app_flutter/config/shared_pref_kay.dart';
import 'package:doctor_app_flutter/core/model/doctor/doctor_profile_model.dart';
import 'package:doctor_app_flutter/core/model/patient/patiant_info_model.dart';
import 'package:doctor_app_flutter/utils/dr_app_shared_pref.dart';

class BaseService {
  String? error;
  bool hasError = false;
  BaseAppClient baseAppClient = BaseAppClient();
  DrAppSharedPreferances sharedPref = DrAppSharedPreferances();
  DoctorProfileModel? doctorProfile;

  List<PatiantInformtion> patientArrivalList = [];

  BaseService() {
    doctorProfile = DoctorProfileModel();
  }

  //TODO add the user login model when we need it
  Future<DoctorProfileModel> getDoctorProfile({bool isGetProfile = false}) async {
    if (isGetProfile) {
      Map<String, dynamic>? profile = await sharedPref.getObj(DOCTOR_PROFILE);
      if (profile != null) {
        doctorProfile = DoctorProfileModel.fromJson(profile);
        if (doctorProfile != null) {
          return doctorProfile!;
        }
      }
    }
    if (doctorProfile == null) {
      Map<String, dynamic>? profile = await sharedPref.getObj(DOCTOR_PROFILE);
      if (profile != null) {
        doctorProfile = DoctorProfileModel.fromJson(profile);
        if (doctorProfile != null) {
          return doctorProfile!;
        }
      }
      return DoctorProfileModel();
    } else {
      return doctorProfile!;
    }
  }
}
