package org.seamframework.sql;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public abstract class AbstractStatement<X> implements Statement {
	
	protected final Table<X> table;
	protected final List<Column<X, ?>> columns = new ArrayList<Column<X,?>>();
	protected final List<Parameter<?>> parameters = new ArrayList<Parameter<?>>();
	
	@Override
	public List<Parameter<?>> getParameters() {
		return parameters;
	}

	protected AbstractStatement(Table<X> table) {
		this.table = table;
	}
	
	public <T> Parameter<T> set(final Column<X, T> column) {
		Parameter<T> result = new Parameter<T>() {
			@Override
			public List<Parameter<?>> getParameters() {
				return Collections.<Parameter<?>>singletonList(this);
			}
			@Override
			public Type<T> getType() {
				return column.getType();
			}
			@Override
			public String toSql() {
				return "?";
			}
		};
		parameters.add(result);
		columns.add(column);
		return result;
	}
	
}
