package eu.dnetlib.domain.functionality;

/**
 * This class represents a template for alert messages.
 * @author thanos
 * @see eu.dnetlib.api.functionality.AlertService
 * @see eu.dnetlib.functionality.alert.alerter.Alerter
 * @see AlertTopic
 * @see AlertSubscription
 *
 */
public class AlertTemplate implements Comparable<AlertTemplate> {
	private String templateId;
	private String templateString;
	
	/**
	 * Construct a new alert template.
	 * @param templateId the unique identifier of this template
	 * @param templateString the actual template
	 */
	public AlertTemplate(final String templateId, final String templateString) {
		this.templateId = templateId;
		this.templateString = templateString;
	}
	
	/**
	 * Construct a new alert template with template identifier and template string set to null.
	 */
	public AlertTemplate() {
		this(null, null);
	}

	/**
	 * Get the unique identifier of this template.
	 * @return the unique identifier of this template
	 */
	public String getTemplateId() {
		return templateId;
	}
	
	/**
	 * Set the unique identifier of this template.
	 * @param templateId the unique identifier of this template
	 */
	public void setTemplateId(final String templateId) {
		this.templateId = templateId;
	}
	
	/**
	 * Get the template string of this template.
	 * @return the template string of this template
	 */
	public String getTemplateString() {
		return templateString;
	}
	
	/**
	 * Set the template string of this template.
	 * @param templateString the template string of this template
	 */
	public void setTemplateString(final String templateString) {
		this.templateString = templateString;
	}
	
	@Override
	public int compareTo(final AlertTemplate template) {
		return templateId.compareTo(template.templateId);
	}
	
	@Override
	public boolean equals(final Object object) {
		if (!(object instanceof AlertTemplate))
			return false;
		AlertTemplate template = (AlertTemplate) object;
		return (templateId == null) ? (template.templateId == null) : templateId.equals(template.templateId);
	}
	
	@Override
	public int hashCode() {
		return (templateId == null) ? 0 : templateId.hashCode();
	}
	
	@Override
	public String toString() {
		return templateId;
	}
}
