package org.croudtrip.api;

import android.content.Context;

import com.google.inject.Binder;
import com.google.inject.Module;
import com.google.inject.Provides;

import org.croudtrip.R;
import org.croudtrip.account.AccountManager;
import org.croudtrip.api.DirectionsResource;
import org.croudtrip.api.GcmRegistrationResource;
import org.croudtrip.api.TripsResource;
import org.croudtrip.api.UsersHeadResource;
import org.croudtrip.api.UsersResource;
import org.croudtrip.api.VehicleResource;

import javax.inject.Inject;

import retrofit.RequestInterceptor;
import retrofit.RestAdapter;

public class ServerModule implements Module {

	@Override
	public void configure(Binder binder) {
		// nothing to do for now
	}


	@Provides
	@Inject
	public RestAdapter provideRestAdapter(final Context context) {
		return new RestAdapter.Builder()
				.setEndpoint(context.getString(R.string.server_address))
				.setRequestInterceptor(new RequestInterceptor() {
					@Override
					public void intercept(RequestFacade request) {
						AccountManager.addAuthorizationHeader(context, request);
					}
				})
				.build();
	}


	@Provides
	@Inject
	public UsersResource provideUsersResource(Context context) {
		return provideRestAdapter(context).create(UsersResource.class);
	}

    @Provides
    @Inject
    public VehicleResource provideVehiclesResource(Context context) {
        return provideRestAdapter(context).create(VehicleResource.class);
    }

	@Provides
	@Inject
	public UsersHeadResource provideUsersHeadResource(Context context) {
		return provideRestAdapter(context).create(UsersHeadResource.class);
	}


	@Provides
	@Inject
	public DirectionsResource provideDirectionsResource(Context context) {
		return provideRestAdapter(context).create(DirectionsResource.class);
	}

    @Provides
    @Inject
    public TripsResource provideTripsResource(Context context) {
        return provideRestAdapter(context).create(TripsResource.class);
    }

	@Provides
	@Inject
	public GcmRegistrationResource provideGcmRegistrationResource(Context context) {
		return provideRestAdapter(context).create(GcmRegistrationResource.class);
	}

}

@@ -228,269 +228,8 @@
 ger;
-%0Aimport org.croudtrip.api.DirectionsResource;%0Aimport org.croudtrip.api.GcmRegistrationResource;%0Aimport org.croudtrip.api.TripsResource;%0Aimport org.croudtrip.api.UsersHeadResource;%0Aimport org.croudtrip.api.UsersResource;%0Aimport org.croudtrip.api.VehicleResource;
 %0A%0Aim
@@ -319,16 +319,60 @@
 Adapter;
+%0Aimport retrofit.converter.JacksonConverter;
 %0A%0Apublic
@@ -873,16 +873,58 @@
 %0A%09%09%09%09%7D)%0A
+%09%09%09%09.setConverter(new JacksonConverter())%0A
 %09%09%09%09.bui

use Jackson for JSON (de-)serialization