package edu.fiu.jtlex.data;

/**
 * Default implementation of {@code IEvent}.
 * 
 * @author arada002
 */
public class Event implements IEvent {

	// Immutable instance fields
	private final int eID;
	private final EventClass eventClass;
	private final String stem; // optional attribute

	/**
	 * Creates a new Event with the specified information.
	 * 
	 * @param eID        id of the event; may not be 0 or negative
	 * @param eventClass the class of the entry may not be <code>null</code>
	 * @param stem       the stem attribute of the event; may not be empty string or
	 *                   all whitespace; may be <code>null</code> if stem is not
	 *                   included in annotation
	 * @throws NullPointerException     if eventClass argument is <code>null</code>
	 * @throws IllegalArgumentException if the stem is empty or all whitespace or
	 *                                  eID is 0 or negative
	 */
	public Event(int eID, EventClass eventClass, String stem) {
		if (eID < 1) {
			throw new IllegalArgumentException("EventID can not be less 1.");
		}
		if (eventClass == null) {
			throw new NullPointerException("Event class needs to be defined.");
		}
		if (stem != null) {
			stem = stem.trim();
			if (stem.length() == 0) {
				throw new IllegalArgumentException("Stem can not be empty string or all whitespace");
			}
		}

		this.eID = eID;
		this.eventClass = eventClass;
		this.stem = stem;

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see edu.fiu.jtlex.data.IEvent#getEventId()
	 */
	public int getId() {
		return eID;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see edu.fiu.jtlex.data.IEvent#getEventIdStr()
	 */
	public String getIdStr() {
		String eId = "e" + eID;
		return eId;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see edu.fiu.jtlex.data.IEvent#getStem()
	 */
	public String getStem() {
		return stem;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see edu.fiu.jtlex.data.IEvent#getType()
	 */
	public EventClass getEventClass() {
		return eventClass;
	}

	/**
	 * Returns string representation of the event object
	 * 
	 * @return event string
	 */
	@Override
	public String toString() {
		String eventString = "EVENT" + EVENT_ID + getId() + CLASS + getEventClass().toString() + STEM + getStem();
		return eventString;
	}

}
