package eu.dnetlib.social.consumer;

import java.util.Collection;

import eu.dnetlib.social.SocialUploadable;

/**
 * @author alessia
 * 
 */
public abstract class AbstractSocialUploader {

	/**
	 * Upload URL of the target social site.
	 */
	private String uploadURL;

	/**
	 * Authenticates this uploader to the target social site with the given user information, then uploads the object.
	 * 
	 * @param userName
	 *            account name
	 * @param password
	 *            account password
	 * @param object
	 *            SocialObject to upload
	 */
	public void publish(final String userName, final String password, final SocialUploadable object) {
		this.authenticate(userName, password);
		this.upload(object);
	}

	/**
	 * Authenticates this uploader to the target social site with the given user information, then uploads the objects.
	 * 
	 * @param userName
	 *            account name
	 * @param password
	 *            account password
	 * @param objects
	 *            Collection of SocialObject to upload
	 */
	public void batchPublish(final String userName, final String password, final Collection<SocialUploadable> objects) {
		this.authenticate(userName, password);
		this.batchUpload(objects);
	}

	/**
	 * Authenticates this uploader with the provided account information. TODO: define how to pass the password, for now
	 * is just clear text.
	 * 
	 * @param userName
	 *            account name
	 * @param password
	 *            account password
	 */
	protected abstract void authenticate(String userName, String password);

	/**
	 * Uploads the given social object to the target social site, assuming authentication succeeded.
	 * 
	 * @param object
	 *            SocialObject instance ready to publish
	 */
	protected abstract void upload(SocialUploadable object);

	/**
	 * Performs a batch upload to the target site of the provided SocialObject instances, assuming authentication
	 * succeeded.
	 * 
	 * @param objects
	 *            Collection of SocialObject instances ready to publish
	 */
	protected abstract void batchUpload(Collection<SocialUploadable> objects);

	public void setUploadURL(final String uploadURL) {
		this.uploadURL = uploadURL;
	}

	public String getUploadURL() {
		return uploadURL;
	}

	/** Constructor. */
	public AbstractSocialUploader() {
		//left blank
	}
}
