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

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.Rating;
import de.uka.ipd.consensus.foundation.schema.User;

/**
 * Event objects of this type are passed to RatingListeners.
 * @author Thomas Much
 * @version 2006-06-14
 * @see RatingListener
 */
public class RatingEvent extends AbstractConsensusFoundationEvent {
	
	private User rater;
	private User ratedUser;
	private Concept ratedConcept;
	private double oldRatingValue;

	
	public RatingEvent(ConsensusFoundationManager cfm, Rating source, User rater, Concept ratedConcept, User ratedUser, double oldRatingValue) {
		super(cfm,source);
		this.rater = rater;
		this.ratedConcept = ratedConcept;
		this.ratedUser = ratedUser;
		this.oldRatingValue = oldRatingValue;
	}

	
	public RatingEvent(ConsensusFoundationManager cfm, Rating source, User rater, Concept ratedConcept) {
		this(cfm,source,rater,ratedConcept,null,Rating.NEUTRAL);
	}


	public RatingEvent(ConsensusFoundationManager cfm, Rating source, User rater, User ratedUser) {
		this(cfm,source,rater,null,ratedUser,Rating.NEUTRAL);
	}


	public RatingEvent(ConsensusFoundationManager cfm, Rating source, User rater, Concept ratedConcept, double oldRatingValue) {
		this(cfm,source,rater,ratedConcept,null,oldRatingValue);
	}

	
	public RatingEvent(ConsensusFoundationManager cfm, Rating source, User rater, User ratedUser, double oldRatingValue) {
		this(cfm,source,rater,null,ratedUser,oldRatingValue);
	}
	
	
	/**
	 * All rating events include a rating that is returned by this method.
	 * @return the rating object that every rating event includes
	 */
	public Rating getRating() {
		return (Rating)getSource();
	}
	
	
	/**
	 * Returns the user who caused the event, i.e. the user who created or changed the rating etc.
	 * @return the user who caused the event
	 */
	public User getUser() {
		return rater;
	}
	
	
	/**
	 * Returns the rated concept if a concept was rated.
	 * @return the rated concept or <code>null</code>
	 */
	public Concept getRatedConcept() {
		return ratedConcept;
	}
	
	
	/**
	 * Returns the rated user if a user was rated by another user.
	 * @return the rated user or <code>null</code>
	 * @see #getUser()
	 */
	public User getRatedUser() {
		return ratedUser;
	}


	/**
	 * If a rating was changed this method returns the rating's old value.
	 * @return the rating's old value if a rating was changed
	 */
	public double getOldRatingValue() {
		return oldRatingValue;
	}

}
