using System;
using System.Collections.Generic;
using System.Text;
using Howest.QueryBuilder.Specifications;

namespace Howest.QueryBuilder.Statements
{
	public class SelectQueryStatement : QueryStatement
	{
		public SelectQueryStatement()
		{
			_selectList = new SelectQueryList();
			_tableReferences = new List<TableReference>();
		}

		private SelectQueryList _selectList;

		public SelectQueryList SelectList
		{
			get { return _selectList; }
		}
	
		private SelectQueryQuantifier _quantifier;

		public SelectQueryQuantifier Quantifier
		{
			get { return _quantifier; }
			set { _quantifier = value; }
		}

		private List<TableReference> _tableReferences;

		public List<TableReference> TableReferences
		{
			get { return _tableReferences; }
		}
	

		public override string GenerateQuery()
		{
			StringBuilder sb = new StringBuilder("SELECT ");
			switch (_quantifier)
			{
				case SelectQueryQuantifier.DISTINCT:
					sb.Append("DISTINCT" + QueryConstants.SPACE);
					break;
				case SelectQueryQuantifier.ALL:
					sb.Append("ALL" + QueryConstants.SPACE);
					break;
				case SelectQueryQuantifier.NONE:
				default:
					break;
			}

			// Add column specifications

			if (true)
			{

			}
			else
				// No columns specified append asteriks
				sb.Append(QueryConstants.ASTERIKS + QueryConstants.SPACE);

			// Add table references

			IEnumerable<TableReference> enumerable = TableReferences;

			IEnumerator<TableReference> enumerator = enumerable.GetEnumerator();

			if (enumerator.MoveNext())
			{
				sb.Append("FROM" + QueryConstants.SPACE);
				sb.Append(enumerator.Current.GenerateInternal());
			}
			while (enumerator.MoveNext())
			{
				sb.Append(QueryConstants.COMMA + QueryConstants.SPACE);
				sb.Append(enumerator.Current.GenerateInternal());
			}
			return sb.ToString();
		}
	}
}
