using System;
using System.Collections;
using System.ComponentModel;

namespace ZANZILib.Protocols.QueryCriteria
{
    /// <summary>
    /// The ZANZI protocol
    /// spesific the queryfields
    /// Has all the search criteria fields as properties for any search
    /// Attributed for the propertygrid display
    /// </summary>
    /// 
    //TODO: locilize all strings
    [DefaultProperty("Category")]
    [Serializable]
    public class clsZanziProt
    {
        #region Variable declaration

        private FilterCritCollection acoltest = new FilterCritCollection();
        private string category = "";
        private string city = "";
        private string country = "";
        private int MaxPrice;
        private int MinPrice;
        private string ProductNameExpression = "";

        //	private string FilterNameExpression = "";
        //	private string ProductNameExpression = "";

        //private string filtermethod = "";
        //private const string TEST = "test";
        //private filtermethod pmeth  = filtermethod.Regular_expressions ;//= new filtermethod() ;

        //private FilterCrit acoltest = new FilterCrit () ;
        //private FilterCrit[] acoltest ;

        #endregion

        #region Enumerations

        #region CharacteristicType enum

        /// <summary>
        /// The searchitemcharacteristics type
        /// Either the characteristics name will be searched or the asosiated value of an searchable item
        /// </summary>
        public enum CharacteristicType
        {
            Name = 0,
            Value = 1
        }

        #endregion

        #region filtermethod enum

        /// <summary>
        /// The filtermethod used for the searchitemcharacteristics specified as a search criteria item
        /// </summary>
        public enum filtermethod
        {
            Regular_expressions = 0,
            Wildcards = 1,
            Include = 2,
            Exclude = 3,
            Min = 4,
            Max = 5
        }

        #endregion

        #endregion

        #region Functions

        #region The clsZanziProt class with all the properties for the propertybox

        //
        //		public override string ToString()
        //		{
        //			//return base.ToString ();
        //			return filterName
        //		}

        // The TypeConverter attribute applied to the DefaultFileName property.
        [TypeConverter(typeof (clsPropertyConverters.CountryConverter)),
         Description("Please select the country to search in."),
        //DefaultValueAttribute("Not Selected"),
         Category("Location")]
        public string Country
        {
            //If region of client is set then get that instead
            get { return country; }
            set { country = value; }
        }

        [Category("Location"),
         Description("Please enter the city to search in."),]
        public string City
        {
            get { return city; }
            set { city = value; }
        }


        [TypeConverter(typeof (clsPropertyConverters.CategoryConverter)),
         Category("Product"),
        //DefaultValueAttribute("Not Selected"),
         Description("Please select the category to search in.")]
        public string Category
        {
            get { return category; }
            set { category = value; }
        }

        [Category("Product"),
         Description("Please enter expression to search for.")]
        public string Name
        {
            get { return ProductNameExpression; }
            set { ProductNameExpression = value; }
        }

        [Category("Filter"),
        //		DefaultValueAttribute("None"),
         Description("Please select the filter method.")]
        //EditorAttribute(typeof(System.ComponentModel.Design.CollectionEditor),typeof(System.Drawing.Design.UITypeEditor))]
            //public FilterCrit Filters
            //public FilterCrit[] Filters
            //	[EditorAttribute(typeof(System.ComponentModel.Design.CollectionEditor), typeof(System.Drawing.Design.UITypeEditor))]
            public FilterCritCollection Filters
        {
            get { return acoltest; }
            set { acoltest = value; }
        }


        //TODO: verander die na beter formaat soos met property projek voorbeeld strukture (extended property attribute class)
        [Category("Price"),
        //		DefaultValueAttribute("None"),
         Description("Please enter the minimum price.")]
        public int Min
        {
            get { return MinPrice; }
            set { MinPrice = value; }
        }

        [Category("Price"),
        //		DefaultValueAttribute("None"),
         Description("Please enter the maximum price.")]
        public int Max
        {
            get { return MaxPrice; }
            set { MaxPrice = value; }
        }

        #endregion

        #region FilterCriteria class

        //TODO: verander die na beter soos met property projek voorbeeld || om kategorie en waarde in te sluit

        /// <summary>
        /// The filter creteria class for the Zanzi protocol
        /// Is used to specify the search criteria for a search
        /// This class must also be used when owm items are spesified that are  availble for searching
        /// by others people on the network
        /// </summary>
        /// 
        //[TypeConverterAttribute(typeof(clsPropertyConverters.FilterCritConverter))]
        [Serializable]
        public class FilterCrit
        {
            //	private  ArrayList myAL = new ArrayList();
            private CharacteristicType chartype;
            private string FilterExpression;
            private string FilterName;
            private filtermethod fmeth = filtermethod.Regular_expressions; //= new filtermethod() ;


            public FilterCrit()
            {
                FilterName = "New filter";
            }

            [Category("Custom"),
             Description("Please enter name for the filter.")]
            public string Name
            {
                get { return FilterName; }
                set { FilterName = value; }
            }


            [Category("Filter"),
             Description("Please enter expression to search for.")]
            public string Value
            {
                get { return FilterExpression; }
                set { FilterExpression = value; }
            }

            [Category("Filter"),
            //		DefaultValueAttribute("None"),
             Description("Please select the filter method.")]
            public filtermethod Method
            {
                get { return fmeth; }
                set { fmeth = value; }
            }

            [Category("Characteristic"),
            //		DefaultValueAttribute("None"),
             Description("Please select the filter method.")]
            public CharacteristicType Type
            {
                get { return chartype; }
                set { chartype = value; }
            }

            public override string ToString()
            {
                //return base.ToString ();
                return FilterName;
            }
        }

        #endregion

        #region FilterCriteria Collection Wrapper

        /// <summary>
        /// A class to facilitate the functionality of the collection editor
        /// In order to display the FilterCriteria collection for editing
        /// </summary>
        [Serializable]
        public class FilterCritCollection : CollectionBase
        {
            public FilterCrit this[int index]
            {
                get { return ((FilterCrit) List[index]); }
                set { List[index] = value; }
            }

            public int Add(FilterCrit value)
            {
                return (List.Add(value));
            }

            public int IndexOf(FilterCrit value)
            {
                return (List.IndexOf(value));
            }

            public void Insert(int index, FilterCrit value)
            {
                List.Insert(index, value);
            }

            public void Remove(FilterCrit value)
            {
                List.Remove(value);
            }

            public bool Contains(FilterCrit value)
            {
                // If value is not of type Int16, this will return false.
                return (List.Contains(value));
            }

            protected override void OnInsert(int index, Object value)
            {
                // Insert additional code to be run only when inserting values.
            }

            protected override void OnRemove(int index, Object value)
            {
                // Insert additional code to be run only when removing values.
            }

            protected override void OnSet(int index, Object oldValue, Object newValue)
            {
                // Insert additional code to be run only when setting values.
            }

//			protected override void OnValidate( Object value )  
//			{
//				if ( value.GetType() != Type.GetType("System.Int16") )
//					throw new ArgumentException( "value must be of type Int16.", "value" );
//			}
        }

        #endregion

        #endregion
    }
}