using System;

namespace Hanna.TextSettings
{
	public class TextSetting
	{	
		private SettingTypes _type		= SettingTypes.Application;
		private string		_name		= string.Empty;
		private string		_section	= string.Empty;
		private string		_value		= string.Empty;

		public TextSetting(SettingTypes SettingType, string Section, string Name, string Value)
		{
			_type		= SettingType;
			_name		= Name;
			_section	= Section;
			_value		= Value;
		}
		public TextSetting(SettingTypes SettingType, string Name, string Value)
		{
			_type		= SettingType;
			_name		= Name;
			_value		= Value;		
		}
		public SettingTypes SettingType
		{
			get{return _type;}
			set{_type = value;}
		}
		public string Name
		{
			get{return _name;}
			set{_name = value;}
		}
		public string Section
		{
			get{return _section;}
			set{_section = value;}
		}
		public string Value
		{
			get { return _value; }
			set { _value = value;}
		}
		public string Key
		{
			get {return _type.ToString() + Constants.KeyDelimiter + _section + Constants.KeyDelimiter + _name;}
		}
		public override bool Equals(object obj)
		{
			if ( ! obj.GetType().Equals(typeof(TextSetting) ) )
				return false;
			else
				return this.Key.Equals(((TextSetting)obj).Key) &&
					   this.Value.Equals(((TextSetting)obj).Value) &&
					   this.SettingType == ((TextSetting)obj).SettingType;	
		}
		public override int GetHashCode()
		{
			byte[] buffer = new byte[2];
			buffer.Initialize();
			char[] wrk = this.ToString().ToCharArray();
			for( int i = 0; i < wrk.Length; i++)
				if ( ( i % 2 ) == 0 )
					buffer[0] = (byte)( buffer[0] ^ (byte)wrk[i]);
				else
					buffer[1] = (byte)( buffer[1] ^ (byte)wrk[i]);
			return ( buffer[0] << 8 ) + buffer[1];
		}
		public override string ToString()
		{
			return string.Format ("SettingType={0}\r\nSection={1}\r\nName={2}\r\nValue={3}",
									this.SettingType.ToString(),
									this.Section,
									this.Name,
									this.Value);
		}
	}
}
