package com.tandbergtv.metadatamanager.search;

import com.tandbergtv.metadatamanager.util.DataTypeConstants;
import com.tandbergtv.metadatamanager.util.DataTypeMappingReader;
import com.tandbergtv.watchpoint.search.Entity;
import com.tandbergtv.workflow.driver.search.SearchOperator;
import com.tandbergtv.workflow.driver.search.SearchType;
import com.tandbergtv.workflow.driver.search.ValueParameter;

public abstract class FieldInfo {
	String ttvxpath;
	String assetType;
	boolean isConjunction;
	
	/**
	 * @return the ttvxpath
	 */
	public String getTtvxpath() {
		return ttvxpath;
	}

	/**
	 * @param ttvxpath the ttvxpath to set
	 */
	public void setTtvxpath(String ttvxpath) {
		this.ttvxpath = ttvxpath;
	}

	/**
	 * @return the assetType
	 */
	public String getAssetType() {
		return assetType;
	}

	/**
	 * @param assetType the assetType to set
	 */
	public void setAssetType(String assetType) {
		this.assetType = assetType;
	}
	
	/**
	 * @return the isConjunction
	 */
	public boolean isConjunction() {
		return isConjunction;
	}

	/**
	 * @param isConjunction the isConjunction to set
	 */
	public void setConjunction(boolean isConjunction) {
		this.isConjunction = isConjunction;
	}

	/**
	 * creates the field entity
	 * @param property
	 * @param assetEntity
	 */
	public abstract void createEntity(String property, Entity assetEntity);
	
	protected ValueParameter addAssetTypeCriteria() {
		if(assetType != null && !assetType.equals("")) {
			return new ValueParameter(AssetSearchKey.PARENT_ASSET_TYPE.toString(), SearchType.STRING, assetType, SearchOperator.EQUAL);
		}
		return null;
	}
	
	/**
	 * 
	 * @return the column name to search in based on the xpath
	 */
	protected String getValueColumnName() {
		String dataType = DataTypeMappingReader.getInstance().determineDataType(ttvxpath);
		if (dataType == null) {
			return "value";
		} else if(dataType.equals(DataTypeConstants.INTEGER)) {
			return "intValue";
		} else if(dataType.equals(DataTypeConstants.FLOAT)) {
			return "floatValue";
		} else if(dataType.equals(DataTypeConstants.DATE)) {
			return "dateValue";
		} else {
			return "value";
		}
	}

	/**
	 * 
	 * @param columnName
	 * @return the searchType for column. 
	 */
	protected SearchType getSearchTypeBasedOnColumn(String columnName) {
		if(columnName.equals("intValue")) { 
				return SearchType.NUMERIC;
		} else if (columnName.equals("floatValue")) { 
				return SearchType.NUMERIC;
		}  else if (columnName.equals("dateValue")) { 
				return SearchType.DATE;
		}  else { 
				return SearchType.STRING;
		}
	}
}
