using JiShe.CollectBus.IoTDB.Model;

namespace JiShe.CollectBus.IoTDB.Provider
{
    /// <summary>
    /// 设备路径构建器
    /// </summary>
    public static class DevicePathBuilder
    {
        /// <summary>
        /// 构建设备路径，由于路径的层级约束规范不能是纯数字字符，所以需要做特殊处理。
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static string GetDevicePath<T>(T entity) where T : IoTEntity
        {
            return $"root.{entity.SystemName.ToLower()}.`{entity.ProjectId}`.`{entity.DeviceType}`.`{entity.DeviceId}`";
        }


        /// <summary>
        /// 获取表名称
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static string GetTableName<T>() where T : IoTEntity
        {
            var type = typeof(T);
            return $"{type.Name.ToLower()}";
        }

        /// <summary>
        /// 获取表名称，用作单侧点表模型特殊处理。
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static string GetDeviceTableName<T>(T entity) where T : IoTEntity
        {
            return $"{entity.SystemName.ToLower()}.`{entity.ProjectId}`.`{entity.DeviceType}`.`{entity.DeviceId}`";
        }
    }

}
