// Path: app/src/main/java/io/github/krtkush/marsexplorer/MarsExplorerApplication.java
// public class MarsExplorerApplication extends Application {
// 
//     // Variable that holds instance of the application class
//     private static MarsExplorerApplication marsExplorerApplicationInstance;
//     // Variable that holds instance of the photos API interface
//     private NASARestApiClient.NASAMarsPhotosApiInterface nasaMarsPhotosApiInterface;
//     // Variable to hold instance of the weather API interface
//     private MarsWeatherClient.MarsWeatherInterface marsWeatherInterface;
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
// 
//         marsExplorerApplicationInstance = this;
// 
//         // Initialize the API interfaces.
//         nasaMarsPhotosApiInterface = NASARestApiClient.getNasaMarsPhotosApiInterface();
//         marsWeatherInterface = MarsWeatherClient.getMarsWeatherInterface();
// 
//         // Initialize calligraphy with the preferred font.
//         CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
//                 .setDefaultFontPath("fonts/Lato-Regular.ttf")
//                 .setFontAttrId(R.attr.fontPath)
//                 .build()
//         );
// 
//         // Initialize timber logging tool only if in debug mode.
//         if(BuildConfig.DEBUG)
//             Timber.plant(new Timber.DebugTree());
// 
//         // Initialize picasso cache indicator and logging only if in debug mode.
//         if(BuildConfig.DEBUG) {
//             Picasso
//                     .with(marsExplorerApplicationInstance)
//                     .setIndicatorsEnabled(true);
// 
//             Picasso
//                     .with(marsExplorerApplicationInstance)
//                     .setLoggingEnabled(true);
//         }
// 
//         // Initialize Leak Canary only if in debug mode.
//         if(BuildConfig.DEBUG)
//             LeakCanary.install(this);
// 
//         // Initialize fabric only if NOT in debug mode.
// /*        if(!BuildConfig.DEBUG)
//             Fabric.with(this, new Crashlytics());*/
//     }
// 
//     /**
//      * @return Instance of the application class (App Context)
//      */
//     public static MarsExplorerApplication getApplicationInstance() {
//         return marsExplorerApplicationInstance;
//     }
// 
//     /**
//      * @return Instance of the NASAMarsPhotosApiInterface
//      */
//     public NASARestApiClient.NASAMarsPhotosApiInterface getNasaMarsPhotosApiInterface() {
//         return nasaMarsPhotosApiInterface;
//     }
// 
//     /**
//      * @return Instance of MarsWeatherInterface
//      */
//     public MarsWeatherClient.MarsWeatherInterface getMarsWeatherInterface() {
//         return marsWeatherInterface;
//     }
// }
// 
// Path: app/src/main/java/io/github/krtkush/marsexplorer/RESTClients/DataModels/WeatherJsonDataModel/MarsWeatherResultDM.java
// @AutoValue
// public abstract class MarsWeatherResultDM {
// 
//     /**
//      * List of the weather report for every SOL
//      */
// 
//     @SerializedName("soles")
//     public abstract List<Soles> weatherReportList();
// 
//     public static TypeAdapter<MarsWeatherResultDM> typeAdapter(Gson gson) {
//         return new AutoValue_MarsWeatherResultDM.GsonTypeAdapter(gson);
//     }
// }
// 
// Path: app/src/main/java/io/github/krtkush/marsexplorer/RESTClients/Interceptors/ResponseCacheInterceptor.java
// public class ResponseCacheInterceptor implements Interceptor {
//     @Override
//     public Response intercept(Chain chain) throws IOException {
// 
//         Request request = chain.request();
//         if(Boolean.valueOf(request.header(RestClientConstants.responseCachingFlagHeader))) {
//             Timber.i("Response cache applied");
//             Response originalResponse = chain.proceed(chain.request());
//             return originalResponse.newBuilder()
//                     .removeHeader(RestClientConstants.responseCachingFlagHeader)
//                     .header("Cache-Control", "public, max-age=" + (3600 * 6))
//                     .build();
//         } else {
//             Timber.i("Response cache not applied");
//             return chain.proceed(chain.request());
//         }
//     }
// }


import com.google.gson.GsonBuilder;
import java.io.File;
import io.github.krtkush.marsexplorer.BuildConfig;
import io.github.krtkush.marsexplorer.MarsExplorerApplication;
import io.github.krtkush.marsexplorer.RESTClients.DataModels.WeatherJsonDataModel.MarsWeatherResultDM;
import io.github.krtkush.marsexplorer.RESTClients.Interceptors.ResponseCacheInterceptor;
import okhttp3.Cache;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.http.GET;
import retrofit2.http.Header;
import rx.Observable;
                    .cache(new Cache(new File(MarsExplorerApplication.getApplicationInstance()
                            .getCacheDir(), RestClientConstants.apiResponsesCache),
                            5 * 1024 * 1024))
                    // Enable logging
                    .addInterceptor(new HttpLoggingInterceptor()
                            .setLevel(logLevel))
                    .build();

            GsonConverterFactory gsonConverterFactory = GsonConverterFactory.create(
                    new GsonBuilder()
                            .registerTypeAdapterFactory(GsonTypeAdapterAdapterFactory.create())
                            .create()
            );

            Retrofit retrofitClient = new Retrofit.Builder()
                    .baseUrl(RestClientConstants.marsWeatherBaseUrl)
                    .client(okHttpClient)
                    .addConverterFactory(gsonConverterFactory)
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                    .build();

            marsWeatherInterface = retrofitClient.create(MarsWeatherInterface.class);
        }

        return marsWeatherInterface;
    }

    public interface MarsWeatherInterface {

        @GET("api.php")
// Path: app/src/main/java/io/github/krtkush/marsexplorer/MarsExplorerApplication.java
// public class MarsExplorerApplication extends Application {
// 
//     // Variable that holds instance of the application class
//     private static MarsExplorerApplication marsExplorerApplicationInstance;
//     // Variable that holds instance of the photos API interface
//     private NASARestApiClient.NASAMarsPhotosApiInterface nasaMarsPhotosApiInterface;
//     // Variable to hold instance of the weather API interface
//     private MarsWeatherClient.MarsWeatherInterface marsWeatherInterface;
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
// 
//         marsExplorerApplicationInstance = this;
// 
//         // Initialize the API interfaces.
//         nasaMarsPhotosApiInterface = NASARestApiClient.getNasaMarsPhotosApiInterface();
//         marsWeatherInterface = MarsWeatherClient.getMarsWeatherInterface();
// 
//         // Initialize calligraphy with the preferred font.
//         CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
//                 .setDefaultFontPath("fonts/Lato-Regular.ttf")
//                 .setFontAttrId(R.attr.fontPath)
//                 .build()
//         );
// 
//         // Initialize timber logging tool only if in debug mode.
//         if(BuildConfig.DEBUG)
//             Timber.plant(new Timber.DebugTree());
// 
//         // Initialize picasso cache indicator and logging only if in debug mode.
//         if(BuildConfig.DEBUG) {
//             Picasso
//                     .with(marsExplorerApplicationInstance)
//                     .setIndicatorsEnabled(true);
// 
//             Picasso
//                     .with(marsExplorerApplicationInstance)
//                     .setLoggingEnabled(true);
//         }
// 
//         // Initialize Leak Canary only if in debug mode.
//         if(BuildConfig.DEBUG)
//             LeakCanary.install(this);
// 
//         // Initialize fabric only if NOT in debug mode.
// /*        if(!BuildConfig.DEBUG)
//             Fabric.with(this, new Crashlytics());*/
//     }
// 
//     /**
//      * @return Instance of the application class (App Context)
//      */
//     public static MarsExplorerApplication getApplicationInstance() {
//         return marsExplorerApplicationInstance;
//     }
// 
//     /**
//      * @return Instance of the NASAMarsPhotosApiInterface
//      */
//     public NASARestApiClient.NASAMarsPhotosApiInterface getNasaMarsPhotosApiInterface() {
//         return nasaMarsPhotosApiInterface;
//     }
// 
//     /**
//      * @return Instance of MarsWeatherInterface
//      */
//     public MarsWeatherClient.MarsWeatherInterface getMarsWeatherInterface() {
//         return marsWeatherInterface;
//     }
// }
// 
// Path: app/src/main/java/io/github/krtkush/marsexplorer/RESTClients/DataModels/WeatherJsonDataModel/MarsWeatherResultDM.java
// @AutoValue
// public abstract class MarsWeatherResultDM {
// 
//     /**
//      * List of the weather report for every SOL
//      */
// 
//     @SerializedName("soles")
//     public abstract List<Soles> weatherReportList();
// 
//     public static TypeAdapter<MarsWeatherResultDM> typeAdapter(Gson gson) {
//         return new AutoValue_MarsWeatherResultDM.GsonTypeAdapter(gson);
//     }
// }
// 
// Path: app/src/main/java/io/github/krtkush/marsexplorer/RESTClients/Interceptors/ResponseCacheInterceptor.java
// public class ResponseCacheInterceptor implements Interceptor {
//     @Override
//     public Response intercept(Chain chain) throws IOException {
// 
//         Request request = chain.request();
//         if(Boolean.valueOf(request.header(RestClientConstants.responseCachingFlagHeader))) {
//             Timber.i("Response cache applied");
//             Response originalResponse = chain.proceed(chain.request());
//             return originalResponse.newBuilder()
//                     .removeHeader(RestClientConstants.responseCachingFlagHeader)
//                     .header("Cache-Control", "public, max-age=" + (3600 * 6))
//                     .build();
//         } else {
//             Timber.i("Response cache not applied");
//             return chain.proceed(chain.request());
//         }
//     }
// }


// Path: app/src/main/java/io/github/krtkush/marsexplorer/RESTClients/MarsWeatherClient.java
import com.google.gson.GsonBuilder;
import java.io.File;
import io.github.krtkush.marsexplorer.BuildConfig;
import io.github.krtkush.marsexplorer.MarsExplorerApplication;
import io.github.krtkush.marsexplorer.RESTClients.DataModels.WeatherJsonDataModel.MarsWeatherResultDM;
import io.github.krtkush.marsexplorer.RESTClients.Interceptors.ResponseCacheInterceptor;
import okhttp3.Cache;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.http.GET;
import retrofit2.http.Header;
import rx.Observable;

                    .cache(new Cache(new File(MarsExplorerApplication.getApplicationInstance()
                            .getCacheDir(), RestClientConstants.apiResponsesCache),
                            5 * 1024 * 1024))
                    // Enable logging
                    .addInterceptor(new HttpLoggingInterceptor()
                            .setLevel(logLevel))
                    .build();

            GsonConverterFactory gsonConverterFactory = GsonConverterFactory.create(
                    new GsonBuilder()
                            .registerTypeAdapterFactory(GsonTypeAdapterAdapterFactory.create())
                            .create()
            );

            Retrofit retrofitClient = new Retrofit.Builder()
                    .baseUrl(RestClientConstants.marsWeatherBaseUrl)
                    .client(okHttpClient)
                    .addConverterFactory(gsonConverterFactory)
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                    .build();

            marsWeatherInterface = retrofitClient.create(MarsWeatherInterface.class);
        }

        return marsWeatherInterface;
    }

    public interface MarsWeatherInterface {

        @GET("api.php")
        Observable<MarsWeatherResultDM> getLatestMarsWeather(