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

namespace Howest.SchemaDiscovery.Configuration
{
	public class DbSchemaProviderElement : ConfigurationElement
	{
		ConfigurationPropertyCollection _properties;

		public DbSchemaProviderElement()
		{

		}

		protected override ConfigurationPropertyCollection Properties
		{
			get
			{
				if (_properties == null)
				{
					ConfigurationPropertyCollection props = new ConfigurationPropertyCollection();
					props.Add(new ConfigurationProperty("name", typeof(string), null, null, new StringValidator(1), ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey));
					props.Add(new ConfigurationProperty("type", typeof(string), null, null, new StringValidator(1), ConfigurationPropertyOptions.IsRequired));
					props.Add(new ConfigurationProperty("default", typeof(bool), false, null, null, ConfigurationPropertyOptions.None));
					_properties = props;
				}
				return _properties;
			}
		}

		[ConfigurationProperty("name", Options = ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey), StringValidator(MinLength = 1)]
		public string Name
		{
			get { return (string)base["name"]; }
			set
			{
				if (string.IsNullOrEmpty(value))
				{
					value = string.Empty;
				}
				base["name"] = value;
			}
		}

		[ConfigurationProperty("type", Options=ConfigurationPropertyOptions.IsRequired), StringValidator(MinLength=1)]
		public string Type
		{
			get { return (string)base["type"]; }
			set
			{
				if (string.IsNullOrEmpty(value))
				{
					value = string.Empty;
				}
				base["type"] = value;
			}
		}

		[ConfigurationProperty("default", DefaultValue=false)]
		public bool IsDefault
		{
			get
			{
				object obj = base["default"];
				return obj == null ? false : (bool)obj;
			}
			set
			{
				base["default"] = value;
			}
		}
	}
}
