package de.stephanlindauer.criticalmaps;

import android.content.Context;
import android.content.SharedPreferences;
import com.jakewharton.picasso.OkHttp3Downloader;
import com.squareup.picasso.Picasso;
import dagger.Module;
import dagger.Provides;
import de.stephanlindauer.criticalmaps.handler.ServerResponseProcessor;
import de.stephanlindauer.criticalmaps.managers.LocationUpdateManager;
import de.stephanlindauer.criticalmaps.model.ChatModel;
import de.stephanlindauer.criticalmaps.model.OtherUsersLocationModel;
import de.stephanlindauer.criticalmaps.model.OwnLocationModel;
import de.stephanlindauer.criticalmaps.model.TwitterModel;
import de.stephanlindauer.criticalmaps.model.UserModel;
import de.stephanlindauer.criticalmaps.provider.EventBusProvider;
import java.util.concurrent.TimeUnit;
import javax.inject.Singleton;
import okhttp3.OkHttpClient;

@Module
public class AppModule {

    private final App app;

    public AppModule(App app) {
        this.app = app;
    }

    @Provides
    @Singleton
    public App provideApp() {
        return app;
    }

    @Provides
    @Singleton
    public OkHttpClient provideOKHttpClient() {
        return new OkHttpClient.Builder()
                .connectTimeout(15, TimeUnit.SECONDS)
                .build();
    }

    @Provides
    @Singleton
    public Picasso providePicasso(App app, OkHttpClient client) {
        return new Picasso.Builder(app)
                .downloader(new OkHttp3Downloader(client))
                .build();
    }

    @Provides
    @Singleton
    public ChatModel provideChatModel() {
        return new ChatModel();
    }

    @Provides
    @Singleton
    public UserModel provideUserModel() {
        return new UserModel(app);
    }


    @Provides
    @Singleton
    public TwitterModel provideTwitterModel() {
        return new TwitterModel();
    }

    @Provides
    @Singleton
    public OwnLocationModel provideOwnLocationModel() {
        return new OwnLocationModel();
    }

    @Provides
    @Singleton
    public ServerResponseProcessor serverResponseProcessor(OtherUsersLocationModel otherUsersLocationModel, EventBusProvider eventService, ChatModel chatModel) {
        return new ServerResponseProcessor(otherUsersLocationModel, eventService, chatModel);
    }

    @Provides
    @Singleton
    public OtherUsersLocationModel provideOtherUsersLocationModel() {
        return new OtherUsersLocationModel();
    }

    @Provides
    @Singleton
    public EventBusProvider provideEventBusProvider() {
        return new EventBusProvider();
    }

    @Provides
    @Singleton
    public LocationUpdateManager provideLocationUpdatesService(
            OwnLocationModel ownLocationModel,
            EventBusProvider eventBusProvider) {
        return new LocationUpdateManager(
                app, ownLocationModel, eventBusProvider);
    }

    @Provides
    @Singleton
    SharedPreferences provideSharedPreferences() {
        return app.getSharedPreferences("Main", Context.MODE_PRIVATE);
    }
}

@@ -1183,33 +1183,16 @@
 uilder()
-%0A                
 .connect
@@ -1220,33 +1220,16 @@
 SECONDS)
-%0A                
 .build()
@@ -1371,33 +1371,16 @@
 der(app)
-%0A                
 .downloa
@@ -1413,33 +1413,16 @@
 client))
-%0A                
 .build()
@@ -1992,16 +1992,29 @@
 ocessor(
+%0A            
 OtherUse
@@ -2053,16 +2053,28 @@
 onModel,
+%0A           
  EventBu
@@ -2096,16 +2096,28 @@
 Service,
+%0A           
  ChatMod
@@ -2603,16 +2603,15 @@
 date
-sService
+Manager
 (%0A  
@@ -2700,24 +2700,24 @@
 Provider) %7B%0A
+
         retu
@@ -2749,25 +2749,8 @@
 ger(
-%0A                
 app,

clean up line breaks