import 'package:diplomaticquarterapp/config/config.dart';
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/HealthCalculator/ClinicCategory.dart';
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/HealthCalculator/DiseasesByClinic.dart';
import 'package:diplomaticquarterapp/core/model/health_calcolator/get_doctor_by_time_model.dart';
import 'package:diplomaticquarterapp/core/model/health_calcolator/get_doctor_by_time_request_model.dart';
import 'package:diplomaticquarterapp/core/model/health_calcolator/get_doctor_list_calcolation_model.dart';
import 'package:diplomaticquarterapp/core/model/health_calcolator/get_doctor_list_calcolation_request_model.dart';
import 'package:diplomaticquarterapp/core/service/base_service.dart';
import 'package:flutter/cupertino.dart';

class BariatricsService extends BaseService {
  List<ClinicCategory> clinicCategoryList = [];
  List<DiseasesByClinic> diseasesList = [];
  List<GetDoctorListModel> doctorList = [];
  List<DoctorListByTimeModel> doctorListByTime = [];

  Future getClinicCategory() async {
    hasError = false;
    Map<String, dynamic> body = Map();
    var languageID = await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');

    body['ClinicID'] = 108; // hint: it is static depend on IONIC project
    body['isDentalAllowedBackend'] = false;
    body['LanguageID'] = languageID == 'ar' ? 1 : 2;

    await baseAppClient.post(GET_CLINIC_CATEGORY, onSuccess: (dynamic response, int statusCode) {
      clinicCategoryList.clear();
      if (response['ClinicCategoryList'] != null)
        response['ClinicCategoryList'].forEach((city) {
          clinicCategoryList.add(ClinicCategory.fromJson(city));
        });
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
  }

  Future getDiseaseByClinicId() async {
    hasError = false;
    Map<String, dynamic> body = Map();
    body['ClinicID'] = 108; // hint: it is static depend on IONIC project

    await baseAppClient.post(GET_DISEASE_BY_CLINIC_ID, onSuccess: (dynamic response, int statusCode) {
      diseasesList.clear();
      if (response['DiseasesByClinicList'] != null)
        response['DiseasesByClinicList'].forEach((city) {
          diseasesList.add(DiseasesByClinic.fromJson(city));
        });
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
  }

  Future searchDoctorsByTime(DiseasesByClinic disease) async {
    hasError = false;
    var languageID = await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');

    Map<String, dynamic> body = Map();
    body['ClinicID'] = 108; // hint: it is static depend on IONIC project
    body['ContinueDentalPlan'] = false;
    body['DiseaseID'] = disease.diseasesID;
    body['IsGetNearAppointment'] = false;
    body['IsSearchAppointmnetByClinicID'] = true;
    body['LanguageID'] = languageID == 'ar' ? 1 : 2;
    body['Latitude'] = 0;
    body['License'] = true;
    body['Longitude'] = 0;
    body['isDentalAllowedBackend'] = false;

    await baseAppClient.post(SEARCH_DOCTOR_BY_TIME, onSuccess: (dynamic response, int statusCode) {},
        onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
  }

  Future getDoctorList({@required DiseasesByClinic disease}) async {
    hasError = false;
    var languageID = await sharedPref.getStringWithDefaultValue(APP_LANGUAGE, 'ar');

    Map<String, dynamic> body = Map();
    body['ClinicID'] = 108; // hint: it is static depend on IONIC project
    body['ContinueDentalPlan'] = false;
    body['IsGetNearAppointment'] = false;
    body['IsSearchAppointmnetByClinicID'] = true;
    body['LanguageID'] = languageID == 'ar' ? 1 : 2;
    body['Latitude'] = 0;
    body['License'] = true;
    body['Longitude'] = 0;
    body['PatientID'] = 0;
    body['isDentalAllowedBackend'] = false;

    if(disease != null)
      body['DiseaseID'] = disease.diseasesID;

    await baseAppClient.post(GET_DOCTOR_LIST_BY_TIME, onSuccess: (dynamic response, int statusCode) {
      doctorListByTime.clear();
      if (response['DoctorList'] != null)
        response['DoctorList'].forEach((city) {
          doctorListByTime.add(DoctorListByTimeModel.fromJson(city));
        });
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
  }
}
