using System;
using System.Collections.Generic;

namespace ObjectModel.Game
{
    /// <summary>
    /// 转换成字段列表
    /// </summary>
    public interface IGameMapField
    {
        public List<GameMapFieldData> ToFields();
    }

    public class GameMapFieldData
    {
        public string Name; // 字段名称
        public bool IsSummary; // 需要纳入统计的字段

        public Func<decimal> GetDecimal;
        public Action<decimal> SetDecimal;

        public Func<int> GetInt;
        public Action<int> SetInt;

        public Func<string> GetString;
        public Action<string> SetString;

        public string ParseStringValue()
        {
            if (GetString != null) return GetString();
            if (GetInt != null) return GetInt().ToString();
            if (GetDecimal != null) return GetDecimal().ToString();
            return "";
        }

        public void SetValue(object value)
        {
            if (SetDecimal != null)
            {
                decimal.TryParse(value.ToString(), out decimal v);
                SetDecimal(v);
            }
            else if (SetInt != null)
            {
                int.TryParse(value.ToString(), out int v);
                SetInt(v);
            }
            else if (SetString != null)
            {
                SetString(value.ToString());
            }
        }
    }
}