// Path: app/src/main/java/com/nilhcem/devoxxfr/utils/Preconditions.java
// public final class Preconditions {
// 
//     private Preconditions() {
//         throw new UnsupportedOperationException();
//     }
// 
//     /**
//      * Ensures the truth of an expression involving one or more parameters to the calling method.
//      *
//      * @param expression a boolean expression
//      * @throws IllegalArgumentException if {@code expression} is false
//      */
//     public static void checkArgument(boolean expression) {
//         if (!expression) {
//             throw new IllegalArgumentException();
//         }
//     }
// 
//     public static void checkNotOnMainThread() {
//         if (BuildConfig.DEBUG) {
//             if (isOnMainThread()) {
//                 throw new IllegalStateException("This method must not be called on the main thread");
//             }
//         }
//     }
// 
//     private static boolean isOnMainThread() {
//         return Thread.currentThread() == Looper.getMainLooper().getThread();
//     }
// }


import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.nilhcem.devoxxfr.BuildConfig;
import com.nilhcem.devoxxfr.utils.Preconditions;
import lombok.ToString;
package com.nilhcem.devoxxfr.data.network;




@ToString
public enum ApiEndpoint {

    PROD(BuildConfig.API_ENDPOINT),
    MOCK(BuildConfig.MOCK_ENDPOINT),
    CUSTOM(null);

    private static final String PREFS_NAME = "api_endpoint";
    private static final String PREFS_KEY_NAME = "name";
    private static final String PREFS_KEY_URL = "url";

    public String url;

    ApiEndpoint(String url) {
        this.url = url;
    }

    public static ApiEndpoint get(Context context) {
        SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
        String prefsName = prefs.getString(PREFS_KEY_NAME, null);
        if (prefsName != null) {
            ApiEndpoint endpoint = valueOf(prefsName);
            if (endpoint == CUSTOM) {
                endpoint.url = prefs.getString(PREFS_KEY_URL, null);
            }
            return endpoint;
        }
        return PROD;
    }

    public static void persist(Context context, @NonNull ApiEndpoint endpoint) {
// Path: app/src/main/java/com/nilhcem/devoxxfr/utils/Preconditions.java
// public final class Preconditions {
// 
//     private Preconditions() {
//         throw new UnsupportedOperationException();
//     }
// 
//     /**
//      * Ensures the truth of an expression involving one or more parameters to the calling method.
//      *
//      * @param expression a boolean expression
//      * @throws IllegalArgumentException if {@code expression} is false
//      */
//     public static void checkArgument(boolean expression) {
//         if (!expression) {
//             throw new IllegalArgumentException();
//         }
//     }
// 
//     public static void checkNotOnMainThread() {
//         if (BuildConfig.DEBUG) {
//             if (isOnMainThread()) {
//                 throw new IllegalStateException("This method must not be called on the main thread");
//             }
//         }
//     }
// 
//     private static boolean isOnMainThread() {
//         return Thread.currentThread() == Looper.getMainLooper().getThread();
//     }
// }


// Path: app/src/internal/java/com/nilhcem/devoxxfr/data/network/ApiEndpoint.java
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.nilhcem.devoxxfr.BuildConfig;
import com.nilhcem.devoxxfr.utils.Preconditions;
import lombok.ToString;

package com.nilhcem.devoxxfr.data.network;




@ToString
public enum ApiEndpoint {

    PROD(BuildConfig.API_ENDPOINT),
    MOCK(BuildConfig.MOCK_ENDPOINT),
    CUSTOM(null);

    private static final String PREFS_NAME = "api_endpoint";
    private static final String PREFS_KEY_NAME = "name";
    private static final String PREFS_KEY_URL = "url";

    public String url;

    ApiEndpoint(String url) {
        this.url = url;
    }

    public static ApiEndpoint get(Context context) {
        SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
        String prefsName = prefs.getString(PREFS_KEY_NAME, null);
        if (prefsName != null) {
            ApiEndpoint endpoint = valueOf(prefsName);
            if (endpoint == CUSTOM) {
                endpoint.url = prefs.getString(PREFS_KEY_URL, null);
            }
            return endpoint;
        }
        return PROD;
    }

    public static void persist(Context context, @NonNull ApiEndpoint endpoint) {
        Preconditions.checkArgument(endpoint != CUSTOM);