package it.mice.voila.runtime.dao;

import java.io.Serializable;


public class CriteriaType {
	/**
	 * Use the default where condition clause.
	 */
    public static final Byte DEFAULT = null;
	/**
	 * Will not use a search condition even attributes are not null.
	 */
    public static final Byte NONE = new Byte("0");
	/**
	 * Force an equal condition by using the entity from value.
	 */
    public static final Byte EQUALS = new Byte("1");
	/**
	 * Force an not equal condition by using the entity from value.
	 */
    public static final Byte NOTEQUALS = new Byte("2");
	/**
	 * Force a start with condition (applicable only for string attributes) by using the entity from attribute value.
	 */
    public static final Byte STARTWITH = new Byte("3");
	/**
	 * Force an end with condition (applicable only for string attributes) by using the entity from attribute value.
	 */
    public static final Byte ENDWITH = new Byte("4");
	/**
	 * Force a contains condition (applicable only for string attributes) by using the entity from attribute value.
	 */
    public static final Byte CONTAINS = new Byte("5");
	/**
	 * Force an IS NULL condition for the attribute.
	 */
    public static final Byte IS_NULL = new Byte("6");
	/**
	 * Force an IS NOT NULL condition for the attribute.
	 */
    public static final Byte IS_NOT_NULL = new Byte("7");
	/**
	 * Force a &gt;= condition by using the entity from attribute value.
	 */
    public static final Byte GREATER_OR_EQUAL_THAN = new Byte("8");
	/**
	 * Force a &lt;= condition by using the entity from attribute value.
	 */
    public static final Byte LESS_OR_EQUAL_THAN = new Byte("9");
	/**
	 * Force a BETWEEN condition by using both entity from and to attribute values.
	 */
    public static final Byte BETWEEN = new Byte("10");
	/**
	 * Force a BETWEEN condition by using both entity from and to attribute values.
	 */
    public static final Byte NOT_BETWEEN = new Byte("14");
	/**
	 * Force a not start with condition (applicable only for string attributes) by using the entity from attribute value.
	 */
    public static final Byte NOT_STARTWITH = new Byte("11");
	/**
	 * Force a not end with condition (applicable only for string attributes) by using the entity from attribute value.
	 */
    public static final Byte NOT_ENDWITH = new Byte("12");
	/**
	 * Force a not contains condition (applicable only for string attributes) by using the entity from attribute value.
	 */
    public static final Byte NOT_CONTAINS = new Byte("13");
    
	public static Byte convertStringCriteriaType(String criteriaValue) {
		if (criteriaValue.equalsIgnoreCase("DEFAULT")) {
			return CriteriaType.DEFAULT;
		}
		if (criteriaValue.equalsIgnoreCase("NONE")) {
			return CriteriaType.NONE;
		}
		if (criteriaValue.equalsIgnoreCase("EQUALS")) {
			return CriteriaType.EQUALS;
		}
		if (criteriaValue.equalsIgnoreCase("NOTEQUALS")) {
			return CriteriaType.NOTEQUALS;
		}
		if (criteriaValue.equalsIgnoreCase("STARTWITH")) {
			return CriteriaType.STARTWITH;
		}
		if (criteriaValue.equalsIgnoreCase("ENDWITH")) {
			return CriteriaType.ENDWITH;
		}
		if (criteriaValue.equalsIgnoreCase("CONTAINS")) {
			return CriteriaType.CONTAINS;
		}
		if (criteriaValue.equalsIgnoreCase("IS_NULL")) {
			return CriteriaType.IS_NULL;
		}
		if (criteriaValue.equalsIgnoreCase("IS_NOT_NULL")) {
			return CriteriaType.IS_NOT_NULL;
		}
		if (criteriaValue.equalsIgnoreCase("GREATER_OR_EQUAL_THAN")) {
			return CriteriaType.GREATER_OR_EQUAL_THAN;
		}
		if (criteriaValue.equalsIgnoreCase("LESS_OR_EQUAL_THAN")) {
			return CriteriaType.LESS_OR_EQUAL_THAN;
		}
		if (criteriaValue.equalsIgnoreCase("BETWEEN")) {
			return CriteriaType.BETWEEN;
		}
		if (criteriaValue.equalsIgnoreCase("NOT_BETWEEN")) {
			return CriteriaType.NOT_BETWEEN;
		}
		if (criteriaValue.equalsIgnoreCase("NOT_STARTWITH")) {
			return CriteriaType.NOT_STARTWITH;
		}
		if (criteriaValue.equalsIgnoreCase("NOT_ENDWITH")) {
			return CriteriaType.NOT_ENDWITH;
		}
		if (criteriaValue.equalsIgnoreCase("NOT_CONTAINS")) {
			return CriteriaType.NOT_CONTAINS;
		}
		throw new IllegalArgumentException("Criteria type is not a valid value. Valid values are: " +
				"DEFAULT, NONE, EQUALS, NOTEQUALS, STARTWITH, ENDWITH, CONTAINS, IS_NULL, IS_NOT_NULL, GREATER_OR_EQUAL_THAN, " +
				"LESS_OR_EQUAL_THAN, BETWEEN, NOT_BETWEEN, NOT_STARTWITH, NOT_ENDWITH, NOT_CONTAINS.");
	}
    
	/**
	 * Force an IN clause for the attribute.
	 * In this case, values to IN on will not be gathered from entities, but from the InClause wrapped list value object.
	 * Example usage is:
	 * <code>
	 *    criteriaMap.put("productCategoryCode", new CriteriaType.InClause(new Object[]{"CAT1", "CAT2"}));
	 * </code>
	 */
    public static class InClause implements Serializable {
		private static final long serialVersionUID = 1L;
		private Object listValue;

    	public InClause(Object listValue) {
			super();
			this.listValue = listValue;
		}

		public Object getListValue() {
			return listValue;
		}
    }
    
	/**
	 * Force a NOT IN clause for the attribute.
	 * In this case, values to NOT IN on will not be gathered from entities, but from the NotInClause wrapped list value object.
	 * Example usage is:
	 * <code>
	 *    criteriaMap.put("productCategoryCode", new CriteriaType.NotInClause(new Object[]{"CAT1", "CAT2"}));
	 * </code>
	 */
    public static class NotInClause implements Serializable {
		private static final long serialVersionUID = 1L;
		private Object listValue;

    	public NotInClause(Object listValue) {
			super();
			this.listValue = listValue;
		}

		public Object getListValue() {
			return listValue;
		}
    }
}
