// Path: app/src/main/java/mk/petrovski/weathergurumvp/data/remote/helper/error/ErrorHandlerHelper.java
// public class ErrorHandlerHelper {
// 
//   Context context;
//   Retrofit retrofit;
// 
//   @Inject public ErrorHandlerHelper(Context context, Retrofit retrofit) {
//     this.context = context;
//     this.retrofit = retrofit;
//   }
// 
//   public String getProperErrorMessage(Throwable throwable) {
//     Throwable properException = getProperException(throwable);
// 
//     if (properException instanceof ServerException) {
//       return context.getString(R.string.error_server);
//     } else if (properException instanceof ServerNotAvailableException) {
//       return context.getString(R.string.error_server_not_available);
//     } else if (properException instanceof InternetConnectionException) {
//       return context.getString(R.string.error_connection);
//     } else if (properException instanceof NotFoundException) {
//       return context.getString(R.string.error_not_found);
//     } else if (properException instanceof UnauthorizedException) {
//       return context.getString(R.string.error_unauthorized);
//     } else if (properException instanceof ParsedResponseException) {
//       return throwable.getMessage();
//     } else {
//       return String.format(context.getString(R.string.error_default), throwable.getMessage());
//     }
//   }
// 
//   public Throwable getProperException(Throwable throwable) {
//     if (throwable instanceof HttpException) {
//       HttpException httpException = (HttpException) throwable;
//       Response response = httpException.response();
// 
//       // try to parse the error
//       Converter<ResponseBody, DataResponseModel> converter =
//           retrofit.responseBodyConverter(DataResponseModel.class, new Annotation[0]);
//       DataResponseModel error = null;
//       try {
//         error = converter.convert(response.errorBody());
//       } catch (IOException | JsonSyntaxException e) {
//         e.printStackTrace();
//       }
// 
//       if (error == null || error.getData() == null || error.getData().getError() == null) {
//         return getThrowable(response.message(), response.code(), throwable);
//       } else {
//         return new ParsedResponseException(error.getData().getError().get(0).getMsg());
//       }
//     } else if (throwable instanceof IOException) {
//       return new InternetConnectionException();
//     } else if (throwable instanceof NetworkErrorException) {
//       return new InternetConnectionException();
//     }
//     return throwable;
//   }
// 
//   @NonNull private Throwable getThrowable(String message, int code, Throwable throwable) {
//     Throwable exception;
//     switch (code) {
//       case 404:
//         exception = new NotFoundException();
//         break;
//       case 401:
//         exception = new UncheckedException(message);
//         break;
//       case 500:
//         exception = new ServerNotAvailableException();
//         break;
//       case 501:
//       case 502:
//       case 503:
//       case 504:
//         exception = new ServerException(throwable);
//         break;
//       default:
//         exception = new UncheckedException(message);
//         break;
//     }
//     return exception;
//   }
// }
// 
// Path: app/src/main/java/mk/petrovski/weathergurumvp/data/remote/model/location_models/SearchApiResponseModel.java
// public class SearchApiResponseModel extends DataResponseModel {
//   private ResultModel search_api;
// 
//   public ResultModel getSearch_api() {
//     return search_api;
//   }
// 
//   public void setSearch_api(ResultModel search_api) {
//     this.search_api = search_api;
//   }
// }
// 
// Path: app/src/main/java/mk/petrovski/weathergurumvp/data/remote/model/weather_models/WeatherResponseModel.java
// public class WeatherResponseModel {
//   private DataModel data;
// 
//   public DataModel getData() {
//     return data;
//   }
// 
//   public void setData(DataModel data) {
//     this.data = data;
//   }
// }


import io.reactivex.Observable;
import javax.inject.Inject;
import mk.petrovski.weathergurumvp.BuildConfig;
import mk.petrovski.weathergurumvp.data.remote.helper.error.ErrorHandlerHelper;
import mk.petrovski.weathergurumvp.data.remote.model.location_models.SearchApiResponseModel;
import mk.petrovski.weathergurumvp.data.remote.model.weather_models.WeatherResponseModel;
package mk.petrovski.weathergurumvp.data.remote;


/**
 * Created by Nikola Petrovski on 2/23/2017.
 */

public class AppApiHelper implements ApiHelper {

  ApiInterface apiInterface;
  ErrorHandlerHelper errorHandlerHelper;

  final String format = "json";
  final String key = BuildConfig.WWO_API_KEY;

  @Inject public AppApiHelper(ApiInterface apiInterface, ErrorHandlerHelper errorHandlerHelper) {
    this.apiInterface = apiInterface;
    this.errorHandlerHelper = errorHandlerHelper;
  }

  @Override public ErrorHandlerHelper getErrorHandlerHelper() {
    return errorHandlerHelper;
  }

  @Override public void setErrorHandler(ErrorHandlerHelper errorHandler) {
    this.errorHandlerHelper = errorHandler;
  }

  @Override
  public Observable<WeatherResponseModel> weatherApiRequest(String latitude, String longitude) {
    String days = "5";
    String tp = "24";
    String cc = "no";
// Path: app/src/main/java/mk/petrovski/weathergurumvp/data/remote/helper/error/ErrorHandlerHelper.java
// public class ErrorHandlerHelper {
// 
//   Context context;
//   Retrofit retrofit;
// 
//   @Inject public ErrorHandlerHelper(Context context, Retrofit retrofit) {
//     this.context = context;
//     this.retrofit = retrofit;
//   }
// 
//   public String getProperErrorMessage(Throwable throwable) {
//     Throwable properException = getProperException(throwable);
// 
//     if (properException instanceof ServerException) {
//       return context.getString(R.string.error_server);
//     } else if (properException instanceof ServerNotAvailableException) {
//       return context.getString(R.string.error_server_not_available);
//     } else if (properException instanceof InternetConnectionException) {
//       return context.getString(R.string.error_connection);
//     } else if (properException instanceof NotFoundException) {
//       return context.getString(R.string.error_not_found);
//     } else if (properException instanceof UnauthorizedException) {
//       return context.getString(R.string.error_unauthorized);
//     } else if (properException instanceof ParsedResponseException) {
//       return throwable.getMessage();
//     } else {
//       return String.format(context.getString(R.string.error_default), throwable.getMessage());
//     }
//   }
// 
//   public Throwable getProperException(Throwable throwable) {
//     if (throwable instanceof HttpException) {
//       HttpException httpException = (HttpException) throwable;
//       Response response = httpException.response();
// 
//       // try to parse the error
//       Converter<ResponseBody, DataResponseModel> converter =
//           retrofit.responseBodyConverter(DataResponseModel.class, new Annotation[0]);
//       DataResponseModel error = null;
//       try {
//         error = converter.convert(response.errorBody());
//       } catch (IOException | JsonSyntaxException e) {
//         e.printStackTrace();
//       }
// 
//       if (error == null || error.getData() == null || error.getData().getError() == null) {
//         return getThrowable(response.message(), response.code(), throwable);
//       } else {
//         return new ParsedResponseException(error.getData().getError().get(0).getMsg());
//       }
//     } else if (throwable instanceof IOException) {
//       return new InternetConnectionException();
//     } else if (throwable instanceof NetworkErrorException) {
//       return new InternetConnectionException();
//     }
//     return throwable;
//   }
// 
//   @NonNull private Throwable getThrowable(String message, int code, Throwable throwable) {
//     Throwable exception;
//     switch (code) {
//       case 404:
//         exception = new NotFoundException();
//         break;
//       case 401:
//         exception = new UncheckedException(message);
//         break;
//       case 500:
//         exception = new ServerNotAvailableException();
//         break;
//       case 501:
//       case 502:
//       case 503:
//       case 504:
//         exception = new ServerException(throwable);
//         break;
//       default:
//         exception = new UncheckedException(message);
//         break;
//     }
//     return exception;
//   }
// }
// 
// Path: app/src/main/java/mk/petrovski/weathergurumvp/data/remote/model/location_models/SearchApiResponseModel.java
// public class SearchApiResponseModel extends DataResponseModel {
//   private ResultModel search_api;
// 
//   public ResultModel getSearch_api() {
//     return search_api;
//   }
// 
//   public void setSearch_api(ResultModel search_api) {
//     this.search_api = search_api;
//   }
// }
// 
// Path: app/src/main/java/mk/petrovski/weathergurumvp/data/remote/model/weather_models/WeatherResponseModel.java
// public class WeatherResponseModel {
//   private DataModel data;
// 
//   public DataModel getData() {
//     return data;
//   }
// 
//   public void setData(DataModel data) {
//     this.data = data;
//   }
// }


// Path: app/src/main/java/mk/petrovski/weathergurumvp/data/remote/AppApiHelper.java
import io.reactivex.Observable;
import javax.inject.Inject;
import mk.petrovski.weathergurumvp.BuildConfig;
import mk.petrovski.weathergurumvp.data.remote.helper.error.ErrorHandlerHelper;
import mk.petrovski.weathergurumvp.data.remote.model.location_models.SearchApiResponseModel;
import mk.petrovski.weathergurumvp.data.remote.model.weather_models.WeatherResponseModel;

package mk.petrovski.weathergurumvp.data.remote;


/**
 * Created by Nikola Petrovski on 2/23/2017.
 */

public class AppApiHelper implements ApiHelper {

  ApiInterface apiInterface;
  ErrorHandlerHelper errorHandlerHelper;

  final String format = "json";
  final String key = BuildConfig.WWO_API_KEY;

  @Inject public AppApiHelper(ApiInterface apiInterface, ErrorHandlerHelper errorHandlerHelper) {
    this.apiInterface = apiInterface;
    this.errorHandlerHelper = errorHandlerHelper;
  }

  @Override public ErrorHandlerHelper getErrorHandlerHelper() {
    return errorHandlerHelper;
  }

  @Override public void setErrorHandler(ErrorHandlerHelper errorHandler) {
    this.errorHandlerHelper = errorHandler;
  }

  @Override
  public Observable<WeatherResponseModel> weatherApiRequest(String latitude, String longitude) {
    String days = "5";
    String tp = "24";
    String cc = "no";
    String location = String.format("%s,%s", latitude, longitude);