using System;
using System.Data;
using System.Collections.Generic;

namespace Cdev.Frameworks.SchemaExplorer
{
    [Serializable]
    public class ViewColumnSchema : DataObjectBase
    {
        private ViewSchema view;

        public ViewColumnSchema(ViewSchema view, string name, DbType dataType, string nativeType, int size, int precision, int scale, bool allowDBNull)
        {
            this.database = view.Database;
            this.view = view;
            this.name = name;
            this.dataType = dataType;
            this.nativeType = nativeType;
            this.size = size;
            this.precision = precision;
            this.scale = scale;
            this.isAllowDBNull = allowDBNull;
            this.extendedProperties = new List<ExtendedProperty>();
        }

        public ViewColumnSchema(ViewSchema view, string name, DbType dataType, string nativeType, int size, byte precision, int scale, bool allowDBNull, ExtendedProperty[] extendedProperties)
            : this(view, name, dataType, nativeType, size, precision, scale, allowDBNull)
        {
            this.extendedProperties = new List<ExtendedProperty>();
            this.extendedProperties.AddRange(extendedProperties);
        }

        internal ViewColumnSchema()
        {
        }

        public virtual ViewSchema View
        {
            get
            {
                return this.view;
            }
        }

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

        public override void Refresh()
        {
        }

        public override string ToString()
        {
            return string.Format("{0}.{1}", this.View, this.Name);
        }
    }
}