package com.sinyuk.yuk.api.oauth;

import android.content.SharedPreferences;

import com.f2prateek.rx.preferences.RxSharedPreferences;
import com.google.gson.Gson;
import com.sinyuk.yuk.BuildConfig;
import com.sinyuk.yuk.api.AccountManager;
import com.sinyuk.yuk.api.DribbleApi;
import com.sinyuk.yuk.utils.IntentFactory;

import javax.inject.Named;
import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Sinyuk on 16/8/23.
 */
@Module
public class OauthModule {

    @Provides
    @Singleton
    @Named("NoCached")
    public OkHttpClient provideOkHttpClientNoCache() {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        if (BuildConfig.DEBUG) {
            HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
            loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
            builder.addInterceptor(loggingInterceptor);
        }
        return builder.build();
    }

    @Provides
    @Singleton
    @Named("OAuth")
    Retrofit provideRetrofitForAuthorization(Gson gson, @Named("NoCached") OkHttpClient okHttpClient) {
        return new Retrofit.Builder()
                .baseUrl(DribbleApi.OAUTH_END_POINT)
                .addConverterFactory(GsonConverterFactory.create(gson))
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .client(okHttpClient)
                .build();
    }

    @Provides
    @Singleton
    public OauthService provideAuthorizationService(@Named("OAuth") Retrofit retrofit) {
        return retrofit.create(OauthService.class);
    }

    @Provides
    @Singleton
    public AccountManager provideAccountManager(OauthService oauthservice,
                                                SharedPreferences preferences,
                                                RxSharedPreferences rxSharedPreferences,
                                                IntentFactory factory) {
        return new AccountManager(oauthservice, preferences, rxSharedPreferences, factory);
    }
}

@@ -32,51 +32,8 @@
 h;%0A%0A
-import android.content.SharedPreferences;%0A%0A
 impo
@@ -232,51 +232,8 @@
 Api;
-%0Aimport com.sinyuk.yuk.utils.IntentFactory;
 %0A%0Aim
@@ -1847,246 +1847,48 @@
 ice,
-%0A                                                SharedPreferences preferences,%0A                                                RxSharedPreferences rxSharedPreferences,%0A                                                IntentFactory factory
+ RxSharedPreferences rxSharedPreferences
 ) %7B%0A
@@ -1938,21 +1938,8 @@
 ice,
- preferences,
  rxS
@@ -1958,17 +1958,8 @@
 nces
-, factory
 );%0A 

Remove params