import 'package:doctor_app_flutter/client/base_app_client.dart';
import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/config/shared_pref_kay.dart';
import 'package:doctor_app_flutter/models/doctor/doctor_profile_model.dart';
import 'package:doctor_app_flutter/models/patient/PatientArrivalEntity.dart';
import 'package:doctor_app_flutter/util/dr_app_shared_pref.dart';

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

  List<PatientArrivalEntity> patientArrivalList = [];

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

  Future getPatientArrivalList(String date) async{
    hasError = false;
    Map<String, dynamic> body = Map();
    body['From'] = date;
    body['To'] = date;
    body['PageIndex'] = 0;
    body['PageSize'] = 0;

    await baseAppClient.post(
      GET_PATIENT_ARRIVAL_LIST,
      onSuccess: (dynamic response, int statusCode) {
        patientArrivalList.clear();

        response['patientArrivalList']['entityList'].forEach((v) {
          PatientArrivalEntity item = PatientArrivalEntity.fromJson(v);
          patientArrivalList.add(item);
        });
      },
      onFailure: (String error, int statusCode) {
        hasError = true;
        this.error = error;
      },
      body: body,
    );
  }

}
