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

import java.net.URI;
import java.net.URISyntaxException;

import be.ac.ulb.code.wit.contacts.Contact;
import be.ac.ulb.code.wit.contacts.Contacts;
import be.ac.ulb.code.wit.resources.ServicePaths;

/**
 * An atom serializer that generates atom entries representing contact groups.
 * 
 * @author fpicalausa
 * 
 */
public abstract class GroupSerializer {
	protected final Contacts contacts;

	/**
	 * Construct a new GroupSerializer, using information from the given
	 * Contacts list.
	 * 
	 * @param contacts
	 *            The contacts list to be used.
	 */
	public GroupSerializer(final Contacts contacts) {
		super();
		this.contacts = contacts;
	}

	/**
	 * Ensures that the given group name is valid
	 * 
	 * @param group
	 *            The group to be checked
	 * @return True if the given group name is valid
	 */
	protected boolean checkGroup(final String group) {
		return (Contact.validGroupName(group));
	}

	/**
	 * Get the URI at which the specified group can be found.
	 * 
	 * @param group
	 *            The group for which the URI is to be retrieved.
	 * @return the URI at which the specified group can be found.
	 */
	public URI getURI(String group) {
		try {
			return new URI(ServicePaths.getURI(ServicePaths.GROUP, "group",
					group));
		} catch (URISyntaxException e) {
			// Should not happen because the URI are well know. Cannot recover
			// from this
			throw new IllegalStateException(e);
		}
	}

	public abstract String makeEntry(String group);

	public abstract String makeFeed();
}
