/**
 * 
 */
package org.gcube.portlets.user.speciesdiscovery.client.event;

import java.util.Date;
import java.util.List;

import org.gcube.portlets.user.speciesdiscovery.shared.DataSourceModel;
import org.gcube.portlets.user.speciesdiscovery.shared.SearchType;
import org.gcube.portlets.user.speciesdiscovery.shared.SpeciesCapability;
import org.gcube.portlets.user.speciesdiscovery.shared.filter.ResultFilter;

import com.google.gwt.event.shared.GwtEvent;

/**
 * @author "Federico De Faveri defaveri@isti.cnr.it"
 *
 */
public class SearchEvent extends GwtEvent<SearchEventHandler> {
	
	public static final GwtEvent.Type<SearchEventHandler> TYPE = new Type<SearchEventHandler>();

	@Override
	public Type<SearchEventHandler> getAssociatedType() {
		return TYPE;
	}

	@Override
	protected void dispatch(SearchEventHandler handler) {
		handler.onSearch(this);	
	}
	
	protected String searchTerm;
	protected SearchType type;
	protected Number upperBoundLongitude; 
	protected Number upperBoundLatitude; 
	protected Number lowerBoundLongitude; 
	protected Number lowerBoundLatitude; 
	protected Date fromDate; 
	protected Date toDate;
	private List<DataSourceModel> lstDataSources;
	private String groupByRank;
	private SpeciesCapability resultType;
	private String query;
	private ResultFilter activeFilterOnResult;

	public SearchEvent(SearchType type, String searchTerm, Number upperBoundLongitude, Number upperBoundLatitude, Number lowerBoundLongitude, Number lowerBoundLatitude,
			Date fromDate, Date toDate, List<DataSourceModel> listDataSources, String rank, SpeciesCapability resultType) {
		this.type = type;
		this.searchTerm = searchTerm;
		this.upperBoundLongitude = upperBoundLongitude;
		this.upperBoundLatitude = upperBoundLatitude;
		this.lowerBoundLongitude = lowerBoundLongitude;
		this.lowerBoundLatitude = lowerBoundLatitude;
		this.fromDate = fromDate;
		this.toDate = toDate;
		this.lstDataSources = listDataSources;
		this.groupByRank = rank;
		this.resultType = resultType;
	}

	public SearchEvent(SearchType byQuery, String query) {
		this.type = byQuery;
		this.query = query;
	}

	/**
	 * @return the type
	 */
	public SearchType getType() {
		return type;
	}

	/**
	 * @return the searchTerm
	 */
	public String getSearchTerm() {
		return searchTerm;
	}

	/**
	 * @return the upperBoundLongitude
	 */
	public Number getUpperBoundLongitude() {
		return upperBoundLongitude;
	}

	/**
	 * @return the upperBoundLatitude
	 */
	public Number getUpperBoundLatitude() {
		return upperBoundLatitude;
	}

	/**
	 * @return the lowerBoundLongitude
	 */
	public Number getLowerBoundLongitude() {
		return lowerBoundLongitude;
	}

	/**
	 * @return the lowerBoundLatitude
	 */
	public Number getLowerBoundLatitude() {
		return lowerBoundLatitude;
	}

	/**
	 * @return the fromDate
	 */
	public Date getFromDate() {
		return fromDate;
	}

	/**
	 * @return the toDate
	 */
	public Date getToDate() {
		return toDate;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("SearchEvent [searchTerm=");
		builder.append(searchTerm);
		builder.append(", type=");
		builder.append(type);
		builder.append(", upperBoundLongitude=");
		builder.append(upperBoundLongitude);
		builder.append(", upperBoundLatitude=");
		builder.append(upperBoundLatitude);
		builder.append(", lowerBoundLongitude=");
		builder.append(lowerBoundLongitude);
		builder.append(", lowerBoundLatitude=");
		builder.append(lowerBoundLatitude);
		builder.append(", fromDate=");
		builder.append(fromDate);
		builder.append(", toDate=");
		builder.append(toDate);
		builder.append("]");
		return builder.toString();
	}

	public List<DataSourceModel> getLstDataSources() {
		return lstDataSources;
	}

	public String getGroupByRank() {
		return groupByRank;
	}

	public SpeciesCapability getResultType() {
		return resultType;
	}

	public String getQuery() {
		return query;
	}
}
