package de.uka.ipd.consensus.foundation.scoring;

import de.uka.ipd.consensus.foundation.AbstractConsensusFoundationEvent;
import de.uka.ipd.consensus.foundation.ConsensusFoundationManager;
import de.uka.ipd.consensus.foundation.schema.Concept;
import de.uka.ipd.consensus.foundation.schema.Occurrence;
import de.uka.ipd.consensus.foundation.schema.Rating;
import de.uka.ipd.consensus.foundation.schema.Synonym;
import de.uka.ipd.consensus.foundation.schema.Topic;
import de.uka.ipd.consensus.foundation.schema.User;

/**
 * Event objects of this type are passed to ScoringListeners.
 * @author Thomas Much
 * @version 2006-06-14
 * @see ScoringListener
 */
public class ScoringEvent extends AbstractConsensusFoundationEvent {

	/**
	 * The event id if a new rating has been assigned to a concept.
	 * @see #getId()
	 */
	public static final int CONCEPT_RATING_SET        =  1;

	
	/**
	 * The event id if the value of an existing concept rating has been changed.
	 * @see #getId()
	 */
	public static final int CONCEPT_RATING_CHANGED    =  2;

	
	/**
	 * The event id if a rating has been removed from a concept.
	 * @see #getId()
	 */
	public static final int CONCEPT_RATING_REMOVED    =  3;

	
	/**
	 * The event id if a new rating has been assigned to a user.
	 * @see #getId()
	 */
	public static final int USER_RATING_SET           =  4;

	
	/**
	 * The event id if the value of an existing user rating has been changed.
	 * @see #getId()
	 */
	public static final int USER_RATING_CHANGED       =  5;

	
	/**
	 * The event id if a rating has been removed from a user.
	 * @see #getId()
	 */
	public static final int USER_RATING_REMOVED       =  6;

	
	/**
	 * The event id if a user created a topic.
	 * @see #getId()
	 */
	public static final int TOPIC_CREATED             =  7;

	
	/**
	 * The event id if a user deleted a topic.
	 * @see #getId()
	 */
	public static final int TOPIC_DELETED             =  8;

	
	/**
	 * The event id if a user merged two topics.
	 * @see #getId()
	 */
	public static final int TOPICS_MERGED             =  9;

	
	/**
	 * The event id if a user created an association.
	 * @see #getId()
	 */
	public static final int ASSOCIATION_CREATED       = 10;

	
	/**
	 * The event id if a user deleted an association.
	 * @see #getId()
	 */
	public static final int ASSOCIATION_DELETED       = 11;

	
	/**
	 * The event id if a user changed the comment of a concept.
	 * @see #getId()
	 */
	public static final int CONCEPT_COMMENT_CHANGED   = 12;

	
	/**
	 * The event id if a user changed the name of a concept.
	 * @see #getId()
	 */
	public static final int CONCEPT_NAME_CHANGED      = 13;

	
	/**
	 * The event id if a user add/removed a type to/from a concept.
	 * @see #getId()
	 */
	public static final int CONCEPT_TYPE_CHANGED      = 14;

	
	/**
	 * The event id if a user changed the classes of a topic.
	 * @see #getId()
	 */
	public static final int TOPIC_CLASS_CHANGED       = 15;

	
	/**
	 * The event id if a topic joins an association as a player.
	 * @see #getId()
	 */
	public static final int ASSOCIATION_TOPIC_ADDED   = 16;

	
	/**
	 * The event id if a topic leaves an association as a player.
	 * @see #getId()
	 */
	public static final int ASSOCIATION_TOPIC_REMOVED = 17;

	
	/**
	 * The event id if an occurrence is created (added to a topic).
	 * @see #getId()
	 */
	public static final int OCCURRENCE_CREATED        = 18;

	
	/**
	 * The event id if the value of an occurrence is changed.
	 * @see #getId()
	 */
	public static final int OCCURRENCE_CHANGED        = 19;

	
	/**
	 * The event id if an occurrence is removed from a topic.
	 * @see #getId()
	 */
	public static final int OCCURRENCE_REMOVED        = 20;

	
	/**
	 * The event id if an attribute is added to a topic.
	 * @see #getId()
	 */
	public static final int ATTRIBUTE_ADDED           = 21;

	
	/**
	 * The event id if the value of an attribute is changed.
	 * @see #getId()
	 */
	public static final int ATTRIBUTE_VALUE_CHANGED   = 22;

	
	/**
	 * The event id if an attribute is removed from a topic.
	 * @see #getId()
	 */
	public static final int ATTRIBUTE_REMOVED         = 23;

	
	/**
	 * The event id if a synonym association is established between two topics.
	 * @see #getId()
	 */
	public static final int SYNONYM_ADDED             = 24;

	
	/**
	 * The event id if a synonym association between two topics is removed.
	 * @see #getId()
	 */
	public static final int SYNONYM_REMOVED           = 25;

	
	private int        id;
	private Concept    concept;
	private User       ratedUser;
	private Rating     rating;
	private double     oldRatingValue;
	private String     oldValue;
	private Topic      oldType;
	private Topic      topic;
	private Occurrence occurrence;
	private Synonym    synonym;


	public ScoringEvent(ConsensusFoundationManager cfm, User source, int id, Concept concept, User ratedUser, Rating rating, double oldRatingValue, String oldValue, Topic oldType, Topic topic, Occurrence occurrence, Synonym synonym) {
		super(cfm,source);
		this.id = id;
		this.concept = concept;
		this.ratedUser = ratedUser;
		this.rating = rating;
		this.oldRatingValue = oldRatingValue;
		this.oldValue = oldValue;
		this.oldType = oldType;
		this.topic = topic;
		this.occurrence = occurrence;
		this.synonym = synonym;
	}
	

	/**
	 * Returns the user who caused the event, i.e. the user who created or rated an element etc.
	 * @return the user who caused the event
	 */
	public User getUser() {
		return (User)getSource();
	}


	/**
	 * Returns the event type (id). See the constants in this class.
	 * @return the event type
	 */
	public int getId() {
		return id;
	}


	/**
	 * If the event happened on a concept, the concept is returned.
	 * Many events have a base concept, like a topic being rated or an association being created.
	 * @return the base concept that this event happened on or <code>null</code>
	 */
	public Concept getConcept() {
		return concept;
	}


	/**
	 * If a user rates another user, this method returns the rated user.
	 * @return the rated user
	 * @see #getUser()
	 */
	public User getRatedUser() {
		return ratedUser;
	}


	/**
	 * If a new rating was created or an existing rating was changed, this method returns the current rating object.
	 * @return the new or changed rating
	 */
	public Rating getRating() {
		return rating;
	}


	/**
	 * If an existing rating was changed, this method returns the old rating value.
	 * @return the old rating value
	 */
	public double getOldRatingValue() {
		return oldRatingValue;
	}


	/**
	 * If a string value (like a concept name or an occurrence value) was changed, this method returns the old value.
	 * @return the old string value
	 */
	public String getOldValue() {
		return oldValue;
	}


	/**
	 * If the type of a concept changes, this method returns the old type.
	 * <code>null</code> is returned if the concept did not have a type before.
	 * @return the old type topic
	 */
	public Topic getOldType() {
		return oldType;
	}


	/**
	 * If an event happens on two topics (e.g. if two topics are merged), this method returns the second topic.
	 * @return the second topic if an event happens on two topics
	 * @see #getConcept()
	 */
	public Topic getTopic() {
		return topic;
	}
	

	/**
	 * Returns the occurrence for occurrence events (creating, changing, removing).
	 * @return an occurrence
	 */
	public Occurrence getOccurrence() {
		return occurrence;
	}


	/**
	 * If a synonym is added or removed, this method returns the Synonym object.
	 * @return the Synonym object
	 */
	public Synonym getSynonym() {
		return synonym;
	}
	
}
