using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace wispro.sp.entity.workflowDefine
{
    public class ConditionExpress
    {
        public ConditionTreeNode Root { get; set; }

        public void AddCondition(ConditionExpress express ,LogicSymbols logic)
        {
            if(express.Root != null)
            {
                if (Root != null)
                {
                    ConditionTreeNode node = new LogicNode() { operate = logic };
                    node.Left = Root;
                    node.Right = express.Root;
                    Root = node;
                }
                else
                {
                    Root = express.Root;
                }
            }
        }
    }

    public class ConditionTreeNode
    {
        public ConditionTreeNode Right { get; set; }

        public ConditionTreeNode Left { get; set; }
    }

    #region 枚举类型
    public enum LogicSymbols
    {
        AND,
        OR,
        NOT
    }

    public enum ComparisonSymbol
    {
        [Description("包含")]
        Contains,
        [Description("等于")]
        Equal,
        [Description("大于")]
        Greater,
        [Description("大于等于")]
        GreaterEqual,
        [Description("小于")]
        Less,
        [Description("小于等于")]
        LessEqual,
        [Description("不等于")]
        NotEqual,
        //[Description("不等于")]
        //In,
        //[Description("不等于")]
        //Between,
        [Description("开头为")]
        StartsWith,
        [Description("结尾为")]
        EndWith,
        [Description("不包含")]
        NotContains
    }

    public enum FieldType
    {
        [Description("用户输入值")]
        ActionInputValue,
        [Description("用户操作")]
        DoAction,
        [Description("绑定对象属性值")]
        BindObjectProperty,
        [Description("流程操作用户")]
        DoActionUser

    }

    public enum UserConditionType 
    {
        [Description("指定个人")]
        Staff,
        [Description("指定部门")]
        Department,
        [Description("指定部门职位")]
        DepartmentPosition,
        [Description("指定用户部门")]
        UserDepartment,
        [Description("指定用户部门职位")]
        UserDepartmentPosition
    }

    public enum UserType
    {
        [Description("指定用户")]
        Staff,
        [Description("登录用户")]
        LoginUser,
        [Description("流程对象人员属性")]
        BindObjectProperty,
        [Description("操作处理人")]
        DoActionUser
    }
    #endregion

    public class LogicNode : ConditionTreeNode
    {
        public LogicSymbols operate { get; set; }
    }

    

    public class FieldNode : ConditionTreeNode
    {
        /// <summary>
        /// 字段名称
        /// </summary>
        public string FieldName { get; set; }
        /// <summary>
        /// 值
        /// </summary>
        public string Value { get; set; }
        /// <summary>
        /// 值类型
        /// </summary>
        public string ValueType { get; set; }

        /// <summary>
        /// 比较符号
        /// </summary>
        public ComparisonSymbol Operator { get; set; }

        /// <summary>
        /// 类型
        /// </summary>
        public FieldType FieldType { get; set; }
    }

    public class UserFieldNode : ConditionTreeNode
    {
        public UserField Field { get; set; }

        /// <summary>
        /// 比较符号
        /// </summary>
        public ComparisonSymbol Operator { get; set; }

        /// <summary>
        /// 值
        /// </summary>
        public string Value { get; set; }
    }

    
    public class UserField
    {
        /// <summary>
        /// 用户条件类型
        /// </summary>
        public UserConditionType UserConditionType { get; set; }

        /// <summary>
        /// 指定用户类型
        /// </summary>
        public UserType UserType { get; set; }

        /// <summary>
        /// 指定用户值
        /// </summary>
        public string UserValue { get; set; }

        /// <summary>
        /// 指定部门值
        /// </summary>
        public string Department { get; set; }

        /// <summary>
        /// 指定职位值
        /// </summary>
        public string Positon { get; set; }

        
        
    }
}
