package com.cloudycrew.cloudycar;

import android.app.Application;

import com.cloudycrew.cloudycar.connectivity.AndroidConnectivityService;
import com.cloudycrew.cloudycar.connectivity.IConnectivityService;
import com.cloudycrew.cloudycar.controllers.RequestController;
import com.cloudycrew.cloudycar.controllers.UserController;
import com.cloudycrew.cloudycar.createrequest.CreateRequestController;
import com.cloudycrew.cloudycar.driversummary.DriverSummaryController;
import com.cloudycrew.cloudycar.elasticsearch.ElasticSearchService;
import com.cloudycrew.cloudycar.elasticsearch.IElasticSearchService;
import com.cloudycrew.cloudycar.fileservices.AndroidFileService;
import com.cloudycrew.cloudycar.fileservices.IFileService;
import com.cloudycrew.cloudycar.models.requests.Request;
import com.cloudycrew.cloudycar.requestdetails.RequestDetailsController;
import com.cloudycrew.cloudycar.requeststorage.CloudRequestService;
import com.cloudycrew.cloudycar.requeststorage.CompositeRequestService;
import com.cloudycrew.cloudycar.requeststorage.IRequestService;
import com.cloudycrew.cloudycar.requeststorage.IRequestStore;
import com.cloudycrew.cloudycar.requeststorage.LocalRequestService;
import com.cloudycrew.cloudycar.requeststorage.RequestStore;
import com.cloudycrew.cloudycar.ridersummary.RiderSummaryController;
import com.cloudycrew.cloudycar.scheduling.AndroidSchedulerProvider;
import com.cloudycrew.cloudycar.scheduling.ISchedulerProvider;
import com.cloudycrew.cloudycar.search.SearchController;
import com.cloudycrew.cloudycar.userprofile.UserProfileController;
import com.cloudycrew.cloudycar.utils.RequestUtils;
import com.searchly.jestdroid.DroidClientConfig;
import com.searchly.jestdroid.JestClientFactory;

import io.searchbox.client.JestClient;

/**
 * Created by George on 2016-10-25.
 */

public class CloudyCarApplication extends Application {
    private IRequestStore requestStore;

    private IRequestStore getRequestStore() {
        if (requestStore == null) {
            requestStore = new RequestStore();
        }
        return requestStore;
    }

    private IFileService getFileService() {
        return new AndroidFileService(getApplicationContext());
    }

    private IRequestService getLocalRequestService() {
        return new LocalRequestService(getFileService());
    }

    private JestClient getJestClient() {
        DroidClientConfig config = new DroidClientConfig.Builder(Constants.ELASTIC_SEARCH_BASE_URL)
                .gson(RequestUtils.getGson())
                .build();


        JestClientFactory factory = new JestClientFactory();
        factory.setDroidClientConfig(config);
        return factory.getObject();
    }

    private IElasticSearchService<Request> getRequestElasticSearchService() {
        return new ElasticSearchService.Builder<Request>()
                .setIndex("cmput301f16t12")
                .setType("request")
                .setTypeClass(Request.class)
                .setJestClient(getJestClient())
                .build();
    }

    private IRequestService getCloudRequestService() {
        return new CloudRequestService("gerg", getRequestElasticSearchService());
    }

    private IConnectivityService getConnectivityService() {
        return new AndroidConnectivityService(getApplicationContext());
    }

    private IRequestService getRequestService() {
        return new CompositeRequestService(getCloudRequestService(),
                getLocalRequestService(),
                getConnectivityService());
    }

    private ISchedulerProvider getSchedulerProvider() {
        return new AndroidSchedulerProvider();
    }

    private RequestController getRequestController() {
        return new RequestController("gerg", getRequestStore(), getRequestService(), getSchedulerProvider());
    }

    private UserController getUserController() {
        return new UserController();
    }

    public DriverSummaryController getDriverSummaryController() {
        return new DriverSummaryController(getRequestController(), getRequestStore());
    }

    public RiderSummaryController getRiderSummaryController() {
        return new RiderSummaryController(getRequestController(), getRequestStore());
    }

    public RequestDetailsController getRequestDetailsController(String requestId) {
        return new RequestDetailsController(requestId, getRequestStore());
    }

    public UserProfileController getUserProfileController() {
        return new UserProfileController(getUserController(), getSchedulerProvider());
    }

    public SearchController getSearchController() {
        return new SearchController();
    }

    public CreateRequestController getCreateRequestController() {
        return new CreateRequestController();
    }
}

@@ -719,32 +719,77 @@
 s.IFileService;%0A
+import com.cloudycrew.cloudycar.models.User;%0A
 import com.cloud
@@ -1614,32 +1614,135 @@
 fileController;%0A
+import com.cloudycrew.cloudycar.users.IUserService;%0Aimport com.cloudycrew.cloudycar.users.UserService;%0A
 import com.cloud
@@ -3168,32 +3168,360 @@
 build();%0A    %7D%0A%0A
+    private IElasticSearchService%3CUser%3E getUserElasticSearchService() %7B%0A        return new ElasticSearchService.Builder%3CUser%3E()%0A                .setIndex(%22cmput301f16t12%22)%0A                .setType(%22user%22)%0A                .setTypeClass(User.class)%0A                .setJestClient(getJestClient())%0A                .build();%0A    %7D%0A%0A
     private IReq
@@ -4272,32 +4272,146 @@
 ider());%0A    %7D%0A%0A
+    private IUserService getUserService() %7B%0A        return new UserService(getUserElasticSearchService());%0A    %7D%0A%0A
     private User
@@ -4469,32 +4469,48 @@
  UserController(
+getUserService()
 );%0A    %7D%0A%0A    pu

Fix resolving dependencies for UserController