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

import '../base_service.dart';

class BloodDonationService extends BaseService {
  //List<GetPatientICProjectsModel> LivechatModelList = List();

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

  List<CitiesModel> CitiesModelList = List();
  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;
    }
  }
}
