using Newtonsoft.Json;
using UnityEngine.Scripting;

[Preserve]
public class PlayerInfo
{
    [JsonProperty("roleId")]
    public string RoleId;

    [JsonProperty("roleName")]
    public string RoleName;

    [JsonProperty("roleLevel")]
    public string RoleLevel;

    [JsonProperty("zoneId")]
    public string ZoneId;

    [JsonProperty("zoneName")]
    public string ZoneName;

    [JsonProperty("serverId")]
    public string ServerId;

    [JsonProperty("serverName")]
    public string ServerName;

    [JsonProperty("balance")]
    public string Balance;

    [JsonProperty("vip")]
    public string Vip;

    [JsonProperty("partyName")]
    public string PartyName;

    [JsonProperty("appVersion")]
    public string AppVersion;

    [JsonProperty("appResVersion")]
    public string AppResVersion;

    [JsonProperty("extendAction")]
    public string ExtendAction;

    [JsonProperty("roleCreateTime")]
    public string RoleCreateTime;

    [JsonProperty("phylum")]
    public string Phylum;

    [JsonProperty("classField")]
    public string ClassField;

    [Preserve]
    [JsonProperty("extra")]
    private string _extra;

    /// <summary>
    /// 获取 Extra 字段的值（只读）
    /// </summary>
    [JsonIgnore]
    public string Extra => _extra;

    /// <summary>
    /// 设置 Extra 字段的值
    /// </summary>
    public void SetExtra(string value)
    {
        _extra = value ?? string.Empty;
    }


    public void AddExtra(string key, int value)
    {
        if (string.IsNullOrEmpty(key)) return;
        _extra += key + ":" + CreateValue(value) + ",";
    }

    public void AddExtra(string key, double value)
    {
        if (string.IsNullOrEmpty(key)) return;
        _extra += key + ":" + CreateValue(value) + ",";
    }


    public void AddExtra(string key, string value)
    {
        if (string.IsNullOrEmpty(key) || value == null) return;
        _extra += key + ":" + CreateValue(value) + ",";
    }

    private string CreateValue(int val)
    {
        return "INT|||" + val;
    }

    private string CreateValue(double val)
    {
        return "DOUBLE|||" + val;
    }

    private string CreateValue(string val)
    {
        return val;
    }
}
