using System;
using System.Collections.Generic;
using System.Text;

namespace Howest.QueryBuilder.Common
{
	public class SelectStatement : Statement
	{
		List<Field> _fields;

		public List<Field> Fields
		{
			get
			{
				if (_fields == null)
					_fields = new List<Field>();
				return _fields;
			}
		}

		private TopFilter _filter;

		public TopFilter Filter
		{
			get { return _filter; }
			set 
			{
				switch (value)
				{
					case TopFilter.Percent:
						if (_filterCount < 0 || _filterCount > 100)
							_filterCount = 100;
						break;
					case TopFilter.Count:
					case TopFilter.None:
					default:
						break;
				}
				_filter = value; 
			}
		}

		private int _filterCount;

		public int FilterRecords
		{
			get { return _filterCount; }
			set 
			{
				switch (_filter)
				{
					case TopFilter.Count:
						if (value < 0)
						{
							throw new ArgumentException("Value must be a nonnegative number", "value");
						}
						break;
					case TopFilter.Percent:
						if (value < 0 || value > 100)
							throw new ArgumentException("If filter is percentage then value must be between 0 and 100.", "value");
						break;
					case TopFilter.None:
					default:
						break;
				}
				_filterCount = value; 
			}
		}


		private bool _allowDuplicates;

		public bool AllowDuplicates
		{
			get { return _allowDuplicates; }
			set { _allowDuplicates = value; }
		}
	
	}
}
