// 此文件由 ThriftIntegratedPipeline 自动生成，请勿手动修改
// 配置类: MergeData
// 数据类: MergeDataItem

using UnityEngine;
using Byway.Config;
using Byway.Thrift.Data;
using UnityGameFramework.Runtime;

namespace CrazyMaple
{
    /// <summary>
    /// MergeData 数据行
    /// </summary>
    public class DRMergeData : DataRowBase
    {
        private MergeDataItem _configData;

        /// <summary>
        /// 唯一标识
        /// </summary>
        public override int Id
        {
            get
            {
                return _configData?.Id ?? 0;
            }
        }

        /// <summary>
        /// Lv
        /// </summary>
        public int Lv
        {
            get
            {
                return _configData?.Lv ?? 0;
            }
        }

        /// <summary>
        /// MaxLv
        /// </summary>
        public int MaxLv
        {
            get
            {
                return _configData?.MaxLv ?? 0;
            }
        }

        /// <summary>
        /// Icon
        /// </summary>
        public string Icon
        {
            get
            {
                return _configData?.Icon ?? "";
            }
        }

        /// <summary>
        /// Color
        /// </summary>
        public string Color
        {
            get
            {
                return _configData?.Color ?? "";
            }
        }

        /// <summary>
        /// Title
        /// </summary>
        public string Title
        {
            get
            {
                return _configData?.Title ?? "";
            }
        }

        /// <summary>
        /// Content
        /// </summary>
        public string Content
        {
            get
            {
                return _configData?.Content ?? "";
            }
        }

        /// <summary>
        /// SellType
        /// </summary>
        public string SellType
        {
            get
            {
                return _configData?.SellType ?? "";
            }
        }

        /// <summary>
        /// SellNum
        /// </summary>
        public int SellNum
        {
            get
            {
                return _configData?.SellNum ?? 0;
            }
        }

        /// <summary>
        /// Star
        /// </summary>
        public int Star
        {
            get
            {
                return _configData?.Star ?? 0;
            }
        }

        /// <summary>
        /// Origin
        /// </summary>
        public string Origin
        {
            get
            {
                return _configData?.Origin ?? "";
            }
        }

        /// <summary>
        /// Capacity
        /// </summary>
        public int Capacity
        {
            get
            {
                return _configData?.Capacity ?? 0;
            }
        }

        /// <summary>
        /// CoolTime
        /// </summary>
        public int CoolTime
        {
            get
            {
                return _configData?.CoolTime ?? 0;
            }
        }

        /// <summary>
        /// CoolNum
        /// </summary>
        public int CoolNum
        {
            get
            {
                return _configData?.CoolNum ?? 0;
            }
        }

        /// <summary>
        /// Emit_List
        /// </summary>
        public string Emit_List
        {
            get
            {
                return _configData?.Emit_List ?? "";
            }
        }

        /// <summary>
        /// SellDiamond
        /// </summary>
        public int SellDiamond
        {
            get
            {
                return _configData?.SellDiamond ?? 0;
            }
        }

        /// <summary>
        /// Relative
        /// </summary>
        public string Relative
        {
            get
            {
                return _configData?.Relative ?? "";
            }
        }

        /// <summary>
        /// Type
        /// </summary>
        public string Type
        {
            get
            {
                return _configData?.Type ?? "";
            }
        }

        /// <summary>
        /// Emit_ID
        /// </summary>
        public string Emit_ID
        {
            get
            {
                return _configData?.Emit_ID ?? "";
            }
        }

        /// <summary>
        /// Emit_Type
        /// </summary>
        public string Emit_Type
        {
            get
            {
                return _configData?.Emit_Type ?? "";
            }
        }

        /// <summary>
        /// Product_Type
        /// </summary>
        public string Product_Type
        {
            get
            {
                return _configData?.Product_Type ?? "";
            }
        }

        /// <summary>
        /// Order_Score
        /// </summary>
        public int Order_Score
        {
            get
            {
                return _configData?.Order_Score ?? 0;
            }
        }

        /// <summary>
        /// Emit_Product
        /// </summary>
        public string Emit_Product
        {
            get
            {
                return _configData?.Emit_Product ?? "";
            }
        }

        /// <summary>
        /// Dynamic
        /// </summary>
        public string Dynamic
        {
            get
            {
                return _configData?.Dynamic ?? "";
            }
        }

        /// <summary>
        /// Dynamic1
        /// </summary>
        public string Dynamic1
        {
            get
            {
                return _configData?.Dynamic1 ?? "";
            }
        }

        /// <summary>
        /// Dynamic2
        /// </summary>
        public string Dynamic2
        {
            get
            {
                return _configData?.Dynamic2 ?? "";
            }
        }

        /// <summary>
        /// Dynamic3
        /// </summary>
        public string Dynamic3
        {
            get
            {
                return _configData?.Dynamic3 ?? "";
            }
        }

        /// <summary>
        /// 从配置加载数据（优先使用传入的配置实例）
        /// </summary>
        public void LoadFromConfig(int id, MergeData config = null)
        {
            if (config == null)
            {
                config = ConfigManager.Instance.GetConfig<MergeData>();
            }
            
            if (config?.Mergedatas != null)
            {
                config.Mergedatas.TryGetValue(id, out _configData);
            }
        }

        /// <summary>
        /// 直接设置配置数据（性能优化：跳过字典查询）
        /// </summary>
        public void SetConfigData(MergeDataItem configData)
        {
            _configData = configData;
        }

        /// <summary>
        /// 解析数据行（优化：使用 userData 传入的配置实例，避免重复调用 GetConfig）
        /// </summary>
        public override bool ParseDataRow(string dataRowString, object userData)
        {
            int id = 0;
            if (!int.TryParse(dataRowString, out id))
            {
                return false;
            }

            // 性能优化：尝试从 userData 获取配置字典，直接获取 Item
            if (userData is System.Collections.Generic.Dictionary<string, object> userDataDict)
            {
                // 优先尝试从缓存的字典直接获取 Item（最快）
                if (userDataDict.TryGetValue("ConfigDict", out object dictObj))
                {
                    var dict = dictObj as System.Collections.Generic.Dictionary<int, MergeDataItem>;
                    if (dict != null && dict.TryGetValue(id, out var item))
                    {
                        _configData = item;
                        return true;
                    }
                }

                // 备选方案：从配置实例获取
                if (userDataDict.TryGetValue("ConfigInstance", out object configObj))
                {
                    var config = configObj as MergeData;
                    if (config != null)
                    {
                        LoadFromConfig(id, config);
                        return _configData != null;
                    }
                }
            }

            // 兜底方案：直接查询（最慢）
            LoadFromConfig(id);
            return _configData != null;
        }
    }
}
