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

namespace JiShe.CollectBus.Analyzers.Shared
{
    /// <summary>
    /// 实体成员信息
    /// </summary>
    public sealed class EntityMemberInfo
    {
        /// <summary>
        /// 名称或者路径
        /// </summary>
        public string NameOrPath { get; set; }

        /// <summary>
        /// 声明的类型
        /// </summary>
        public Type DeclaredType { get; set; }

        /// <summary>
        /// 声明的类型的名称
        /// </summary>
        public string DeclaredTypeName { get; }

        /// <summary>
        /// 获取值
        /// </summary>
        public Func<object, object> Getter { get; }

        /// <summary>
        /// 设置值
        /// </summary>
        public Action<object, object> Setter { get; }

        /// <summary>
        /// 自定义Attribute集合
        /// </summary>
        public List<Attribute> CustomAttributes { get; set; }


        public EntityMemberInfo(
            string nameOrPath,
            Type declaredType,
            string declaredTypeName,
            Func<object, object> getter,
            Action<object, object> setter)
        {
            NameOrPath = nameOrPath;
            this.DeclaredType = declaredType;
            DeclaredTypeName = declaredTypeName;
            Getter = getter;
            Setter = setter;
        }

        public object GetValue(object entity) => Getter(entity);
        public void SetValue(object entity, object value) => Setter(entity, value);
    }
}
