/* ************************************************************************
#
#  DivConq
#
#  http://divconq.com/
#
#  Copyright:
#    Copyright 2012 eTimeline, LLC. All rights reserved.
#
#  License:
#    See the license.txt file in the project's top-level directory for details.
#
#  Authors:
#    * Andy White
#
************************************************************************ */
package divconq.db.query;

import divconq.struct.RecordStruct;
import divconq.struct.Struct;
import divconq.util.StringUtil;

/**
 * A database field to select in a query.
 * Field may be formated and also may hold a display name.
 * 
 * @author Andy
 *
 */
public class SelectField implements ISelectField {
	protected RecordStruct column = new RecordStruct();
	
	/**
	 * @param field field name
	 */
	public SelectField(String field) {
		this.column.setField("Field", field);
	}
	
	/**
	 * @param field field name
	 * @param name display (return) name
	 */
	public SelectField(String field, String name) {
		this(field);
		
		if (StringUtil.isNotEmpty(name))
			this.column.setField("Name", name);
	}
	
	/**
	 * @param field field name
	 * @param name display (return) name
	 * @param format formatting for return value
	 */
	public SelectField(String field, String name, String format) {
		this(field, name);
		
		if (StringUtil.isNotEmpty(format))
			this.column.setField("Format", format);
	}
	
	/* (non-Javadoc)
	 * @see divconq.db.query.ISelectItem#getSelection()
	 */
	@Override
	public Struct getParams() {
		return this.column;
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return this.column.toString();
	}
}
