// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/helpers/ServerConfigsHelper.java
// public class ServerConfigsHelper {
// 
//     public static String getAPIEndpoint() {
//         return FirebaseRemoteConfig.getInstance().getString(FIREBASE_SERVER_CONFIG);
//     }
// 
//     public static void removeAPIEndpoint(Context context) {
//         SharedPreferencesHelper.removeSharedPreferenceObject(context, SP_SP_SERVER_CONFIG);
//     }
// 
//     public static int getProUsersNumberFromSharedPreferences(Context context) {
//         return SharedPreferencesHelper.getSharedPreferenceInt(context, SP_SP_PRO_USERS_NUMBER, 2);
//     }
// 
//     public static void setProUsersInSharedPreferences(Context context, int number) {
//         SharedPreferencesHelper.setSharedPreferenceInt(context, SP_SP_PRO_USERS_NUMBER, number);
//     }
// 
// }


import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.jaus.albertogiunta.justintrain_oraritreni.BuildConfig;
import com.jaus.albertogiunta.justintrain_oraritreni.utils.helpers.ServerConfigsHelper;
import org.joda.time.DateTime;
import io.reactivex.schedulers.Schedulers;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
package com.jaus.albertogiunta.justintrain_oraritreni.networking;





public class APINetworkingFactory {

    /**
     * Creates a retrofit service from an arbitrary class (clazz)
     *
     * @param clazz    Java interface of the retrofit service
     * @return retrofit service with defined endpoint
     */
    public static <T> T createRetrofitService(final Class<T> clazz) {

        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC);
        OkHttpClient client = new OkHttpClient.Builder()
                .addInterceptor(loggingInterceptor)
                .addInterceptor(chain -> {
                    Request original = chain.request();

                    // Request customization: add request headers
                    Request.Builder requestBuilder = original.newBuilder()
                            .header(BuildConfig.AUTH_FIELD_NAME, BuildConfig.AUTH_TOKEN)
                            .method(original.method(), original.body());

                    Request request = requestBuilder.build();
                    return chain.proceed(request);
                })
                .build();

        Gson gson = new GsonBuilder()
                .registerTypeAdapter(DateTime.class, new DateTimeAdapter())
                .registerTypeAdapterFactory(new PostProcessingEnabler())
                .create();

        final Retrofit restAdapter = new Retrofit.Builder()
// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/utils/helpers/ServerConfigsHelper.java
// public class ServerConfigsHelper {
// 
//     public static String getAPIEndpoint() {
//         return FirebaseRemoteConfig.getInstance().getString(FIREBASE_SERVER_CONFIG);
//     }
// 
//     public static void removeAPIEndpoint(Context context) {
//         SharedPreferencesHelper.removeSharedPreferenceObject(context, SP_SP_SERVER_CONFIG);
//     }
// 
//     public static int getProUsersNumberFromSharedPreferences(Context context) {
//         return SharedPreferencesHelper.getSharedPreferenceInt(context, SP_SP_PRO_USERS_NUMBER, 2);
//     }
// 
//     public static void setProUsersInSharedPreferences(Context context, int number) {
//         SharedPreferencesHelper.setSharedPreferenceInt(context, SP_SP_PRO_USERS_NUMBER, number);
//     }
// 
// }


// Path: app/src/main/java/com/jaus/albertogiunta/justintrain_oraritreni/networking/APINetworkingFactory.java
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.jaus.albertogiunta.justintrain_oraritreni.BuildConfig;
import com.jaus.albertogiunta.justintrain_oraritreni.utils.helpers.ServerConfigsHelper;
import org.joda.time.DateTime;
import io.reactivex.schedulers.Schedulers;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

package com.jaus.albertogiunta.justintrain_oraritreni.networking;





public class APINetworkingFactory {

    /**
     * Creates a retrofit service from an arbitrary class (clazz)
     *
     * @param clazz    Java interface of the retrofit service
     * @return retrofit service with defined endpoint
     */
    public static <T> T createRetrofitService(final Class<T> clazz) {

        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC);
        OkHttpClient client = new OkHttpClient.Builder()
                .addInterceptor(loggingInterceptor)
                .addInterceptor(chain -> {
                    Request original = chain.request();

                    // Request customization: add request headers
                    Request.Builder requestBuilder = original.newBuilder()
                            .header(BuildConfig.AUTH_FIELD_NAME, BuildConfig.AUTH_TOKEN)
                            .method(original.method(), original.body());

                    Request request = requestBuilder.build();
                    return chain.proceed(request);
                })
                .build();

        Gson gson = new GsonBuilder()
                .registerTypeAdapter(DateTime.class, new DateTimeAdapter())
                .registerTypeAdapterFactory(new PostProcessingEnabler())
                .create();

        final Retrofit restAdapter = new Retrofit.Builder()
                .baseUrl(ServerConfigsHelper.getAPIEndpoint())