package be.ac.ulb.code.wit.resources;

import java.io.Reader;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.apache.abdera.util.Constants;

import com.sun.jersey.api.core.HttpContext;

@Path(ServicePaths.CONTACTS)
public class Contacts {
	private final GroupContacts handler = new GroupContacts();

	@Context
	HttpContext context;

	@GET
	@Produces({ Constants.FEED_MEDIA_TYPE, MediaType.APPLICATION_JSON })
	public Response getContacts() {
		return handler.getContacts(context,
				be.ac.ulb.code.wit.contacts.Contacts.GROUP_ALLCONTACTS);
	}

	@POST
	@Consumes({ Constants.ENTRY_MEDIA_TYPE, MediaType.APPLICATION_JSON })
	@Produces({ Constants.ENTRY_MEDIA_TYPE, MediaType.APPLICATION_JSON })
	public Response createContact(final Reader data) {
		return handler.createGroupContacts(context,
				be.ac.ulb.code.wit.contacts.Contacts.GROUP_ALLCONTACTS, data);
	}
}
