package ta.transition.sync;

import com.google.common.base.Preconditions;

public class SyncExpression {

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((event == null) ? 0 : event.hashCode());
		result = prime * result + ((operator == null) ? 0 : operator.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		SyncExpression other = (SyncExpression) obj;
		if (event == null) {
			if (other.event != null)
				return false;
		} else if (!event.equals(other.event))
			return false;
		if (operator == null) {
			if (other.operator != null)
				return false;
		} else if (!operator.equals(other.operator))
			return false;
		return true;
	}


	private final String event;
	private final String operator;

	public SyncExpression(String event, String operator) {
		Preconditions.checkNotNull(event, "The event cannot be null");
		Preconditions.checkNotNull(operator, "The operator cannot be null");
		this.event = event;
		this.operator = operator;

	}

	public String getEvent() {
		return this.event;
	}

	public String getOperator() {
		return operator;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String toString() {
		return event + operator;
	}
	
	
	public enum Operator {
		SEND("?"), RECEIVED("!"), TAU("TAU");

		private final String operaor;

		private Operator(String operator) {
			this.operaor = operator;
		}

		public static Operator parse(String value){
			switch(value){
				case "?": return Operator.SEND;
				case "!": return Operator.RECEIVED;
				default: return Operator.TAU;
			}
		}
		public String toString() {
			return this.operaor;
		}
	}
}
