import 'package:hmg_patient_app/config/config.dart';
import 'package:hmg_patient_app/core/model/blooddonation/get_all_cities.dart';

import '../base_service.dart';

class BloodDonationService extends BaseService {
  //List<GetPatientICProjectsModel> LivechatModelList =[];

//  Map<String, dynamic> body = Map();

  List<CitiesModel> CitiesModelList =[];
  Map<String, dynamic> body = Map();

  Future getAllCitiesOrders() async {
    hasError = false;
    body['ListCities'] = false;
    body["IsPublicRequest"] = true;
    await baseAppClient.post(GET_CITIES_REQUEST, onSuccess: (dynamic response, int statusCode) {
      CitiesModelList.clear();
      response['ListCities'].forEach((vital) {
        CitiesModelList.add(CitiesModel.fromJson(vital));
      });
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
  }

  Future bloodDonationSave(request) async {
    var localRes;
    try {
      await baseAppClient.post(SAVE_BLOOD_REQUEST, onSuccess: (dynamic response, int statusCode) {
        localRes = response;
      }, onFailure: (String error, int statusCode) {
        localRes = error;
        return Future.value(error);
      }, body: request);
      return Future.value(localRes);
    } catch (error) {
      throw error;
    }
  }

  Future getAgreement() async {
    var localRes;
    try {
      await baseAppClient.post(GET_BLOOD_AGREEMENT, onSuccess: (dynamic response, int statusCode) {
        localRes = response;
      }, onFailure: (String error, int statusCode) {
        localRes = error;
        return Future.value(error);
      }, body: {});
      return Future.value(localRes);
    } catch (error) {
      throw error;
    }
  }

  Future saveAgreement(request) async {
    var localRes;
    try {
      await baseAppClient.post(SAVE_BLOOD_AGREEMENT, onSuccess: (dynamic response, int statusCode) {
        localRes = response;
      }, onFailure: (String error, int statusCode) {
        localRes = error;
        return Future.value(error);
      }, body: request);
      return Future.value(localRes);
    } catch (error) {
      throw error;
    }
  }

  Future<Map> getBloodDonationProjectsList() async {
    Map<String, dynamic> request;
    request = {};
    dynamic localRes;
    await baseAppClient.post(GET_BLOOD_DONATION_PROJECTS_LIST, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);

    return Future.value(localRes);
  }

  Future<Map> getBloodDonationFreeSlots(int clinicID, int projectID) async {
    Map<String, dynamic> request;
    request = {"ClinicID": clinicID, "ProjectID": projectID};
    dynamic localRes;
    await baseAppClient.post(GET_BLOOD_DONATION_FREE_SLOTS, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);

    return Future.value(localRes);
  }

}
