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

namespace Howest.SchemaDiscovery.DbObjects
{
	public class Column
	{
		public Column(Table table)
		{
			if (table == null)
				throw new ArgumentNullException("table");
			_table = table;
		}

		private string _name;

		public string Name
		{
			get { return _name; }
			set { _name = value; }
		}

		private DbDataType _type;
		public DbDataType DbDataType
		{
			get { return _type; }
			set { _type = value; }
		}
	

		private bool _isNullable;
		
		public bool IsNullable
		{
			get { return _isNullable; }
			set { _isNullable = value; }
		}
	

		private bool _isPrimaryKey;

		public bool IsPrimaryKey
		{
			get { return _isPrimaryKey; }
			set { _isPrimaryKey = value; }
		}

		private bool _isForeignKey;

		public bool IsForeignKey
		{
			get { return _isForeignKey; }
			set { _isForeignKey = value; }
		}

		private bool _isUnique;

		public bool IsUnique
		{
			get { return _isUnique; }
			set { _isUnique = value; }
		}

		private bool _isIdentity;

		public bool IsIdentity
		{
			get { return _isIdentity; }
			set { _isIdentity = value; }
		}

		private bool _isReadOnly;

		public bool IsReadOnly
		{
			get { return _isReadOnly; }
			set { _isReadOnly = value; }
		}
	

		private Table _table;
		public Table Table
		{
			get { return _table; }
		}

		public override bool Equals(object obj)
		{
			if (obj == null)
				return false;
			if (!(obj is Column))
				return false;
			Column col = obj as Column;
			//if (col == null)
			//    return false;
			return this.Table == col.Table && this.Name == col.Name;
		}

		public override int GetHashCode()
		{
			return this.Table.GetHashCode() ^ this.Name.GetHashCode();
		}

		public static bool operator ==(Column col1, Column col2)
		{
			if (object.ReferenceEquals(col1, col2))
				return true;
			if ((object)col1 == null || (object)col2 == null)
				return false;
			return col1.Equals(col2);
		}

		public static bool operator !=(Column col1, Column col2)
		{
			return !(col1==col2);
		}
	}
}
