using Apache.IoTDB;
using JiShe.CollectBus.Analyzers.Shared;

namespace JiShe.CollectBus.IoTDB.Provider
{
    /// <summary>
    /// 设备元数据
    /// </summary>
    public sealed class DeviceMetadata
    {
        /// <summary>
        /// 实体类名称
        /// </summary>
        public string EntityName { get; set; }

        /// <summary>
        /// 设备表名或树路径，如果实体没有添加TableNameOrTreePath,此处为空
        /// </summary>
        public string TableNameOrTreePath { get; set; }

        /// <summary>
        /// 实体类型枚举
        /// </summary>
        public EntityTypeEnum? EntityType  { get; set; }

        /// <summary>
        /// 是否有单测量值
        /// </summary>
        public bool IsSingleMeasuring { get; set; }

        /// <summary>
        /// 测量值集合，用于构建Table的测量值，也就是columnNames参数
        /// </summary>
        public List<string> ColumnNames { get; set; } = new();

        /// <summary>
        /// 列类型集合，用于构建Table的列类型，也就是columnCategories参数
        /// </summary>
        public List<ColumnCategory> ColumnCategories { get; } = new();

        /// <summary>
        /// 值类型集合，用于构建Table的值类型，也就是dataTypes参数
        /// </summary>
        public List<TSDataType> DataTypes { get; set; } = new();

        /// <summary>
        /// 列处理信息集合
        /// </summary>
        public List<ColumnProcessor> Processors { get; } = new List<ColumnProcessor>();
    }

    /// <summary>
    /// 列处理信息结构
    /// </summary>
    public struct ColumnProcessor
    {
        /// <summary>
        /// 列名
        /// </summary>
        public string ColumnName;

        /// <summary>
        /// 数据类型
        /// </summary>
        public TSDataType TSDataType { get; set;}

        /// <summary>
        /// 值获取委托（参数：实体对象）
        /// </summary>
        public Func<object, object> ValueGetter;

        /// <summary>
        /// 值设置委托（参数：实体对象，新值）
        /// </summary>
        public Action<object, object> ValueSetter;

        /// <summary>
        /// 类型转换委托
        /// </summary>
        public Func<object, object> GetConverter;

        /// <summary>
        /// 类型转换委托
        /// </summary>
        public Func<object, object> SetConverter;

        /// <summary>
        /// 是否单测点
        /// </summary>
        public bool IsSingleMeasuring;

        /// <summary>
        /// 单测点名称委托
        /// </summary>
        public Func<object, object> SingleMeasuringNameGetter;
    }
}
