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

namespace CommonLang.Property
{
    /// <summary>
    /// 编辑器支持,描述性文件
    /// </summary>
    [AttributeUsage(AttributeTargets.All)]
    public class DescAttribute : System.Attribute
    {
        readonly string desc;
        readonly string category;
        readonly bool editable;
        readonly string detail;

        public DescAttribute(string desc)
            : this(desc, "", true, null)
        {
        }
        public DescAttribute(string desc, string category)
            : this(desc, category, true, null)
        {
        }
        public DescAttribute(string desc, string category, bool editable)
            : this(desc, category, editable, null)
        {
        }
        public DescAttribute(string desc, string category, bool editable, string detail)
        {
            this.desc = desc;
            this.category = category;
            this.editable = editable;
            this.detail = detail;
        }

        public string Desc
        {
            get { return desc; }
        }
        public string Category
        {
            get { return category; }
        }
        public bool Editable
        {
            get { return editable; }
        }
        public string Detail
        {
            get { return detail; }
        }
    }

    /// <summary>
    /// 某个字段依赖于某个开关(字段或者属性)
    /// </summary>
    [AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
    public class DependOnPropertyAttribute : System.Attribute
    {
        readonly string property_name;
        readonly bool expect;
        public DependOnPropertyAttribute(string property_name, bool expect = true)
        {
            this.property_name = property_name;
            this.expect = expect;
        }
        public string PropertyName { get { return property_name; } }
        public bool Expect { get { return expect; } }
    }

    /// <summary>
    /// 某个字段依赖于某个开关(字段或者属性)
    /// </summary>
    [AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
    public class DependOnPropertyExtAttribute : System.Attribute
    {
        readonly string property_name;
        readonly int expect;
        public DependOnPropertyExtAttribute(string property_name, int expect = 0)
        {
            this.property_name = property_name;
            this.expect = expect;
        }
        public string PropertyName { get { return property_name; } }
        public int Expect { get { return expect; } }
    }

    /// <summary>
    /// 编辑器支持,描述列表的成员类型
    /// </summary>
    [AttributeUsage(AttributeTargets.Field)]
    public class ListAttribute : System.Attribute
    {
        private List<Type> elementTypes;

        public ListAttribute(params Type[] types)
        {
            HashMap<Type, Type> typeSet = new HashMap<Type, Type>();
            foreach (Type type in types)
            {
                if (type.IsAbstract)
                {
                    foreach (Type sub in ReflectionUtil.GetNoneVirtualSubTypes(type))
                    {
                        typeSet.Add(sub, sub);
                    }
                }
                else
                {
                    typeSet.Add(type, type);
                }
            }
            this.elementTypes = new List<Type>(typeSet.Keys);
        }

        public List<Type> ElementTypes
        {
            get { return elementTypes; }
        }
    }

    /// <summary>
    /// 编辑器支持,描述一个类的主键是什么
    /// </summary>
    [AttributeUsage(AttributeTargets.Class)]
    public class TableClassAttribute : System.Attribute
    {
        private string id_field;

        public TableClassAttribute(string key)
        {
            this.id_field = key;
        }

        public string PrimaryKey
        {
            get { return id_field; }
        }
    }

    /// <summary>
    /// 编辑器支持,此类型是可折叠
    /// </summary>
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Field | AttributeTargets.Property)]
    public class ExpandableAttribute : System.Attribute
    {

    }

    /// <summary>
    /// 编辑器支持,字段是否可删除或改变
    /// </summary>
    [AttributeUsage(AttributeTargets.Field)]
    public class NotNullAttribute : System.Attribute
    {

    }

    /// <summary>
    /// 列取当前字段可能的值
    /// </summary>
    [AttributeUsage(AttributeTargets.Field)]
    public class OptionalValueAttribute : System.Attribute
    {
        public string[] Values { get; private set; }

        public OptionalValueAttribute(params string[] args)
        {
            this.Values = args;
        }
    }

    //----------------------------------------------------------------------------
    #region Type

    /// <summary>
    /// 标识 Field 字段为颜色
    /// </summary>
    [AttributeUsage(AttributeTargets.Field)]
    public class Int32ColorAttribute : System.Attribute
    {

    }

    /// <summary>
    /// 标识 Field 字段为文件
    /// </summary>
    [AttributeUsage(AttributeTargets.Field)]
    public class FilePathAttribute : System.Attribute
    {

    }

    /// <summary>
    /// 标识 Field 字段为目录
    /// </summary>
    [AttributeUsage(AttributeTargets.Field)]
    public class DirectoryPathAttribute : System.Attribute
    {

    }

    #endregion
}