using ThingsGateway.NewLife.Data;

namespace ThingsGateway.NewLife.Caching.Queues;

/// <summary>等待信息</summary>
public class PendingInfo
{
    #region 属性
    /// <summary>个数</summary>
    public Int32 Count { get; set; }

    /// <summary>开始Id</summary>
    public String? StartId { get; set; }

    /// <summary>结束Id</summary>
    public String? EndId { get; set; }

    /// <summary>消费者挂起情况</summary>
    public IDictionary<String, Int32>? Consumers { get; set; }
    #endregion

    #region 方法
    /// <summary>分析</summary>
    /// <param name="vs"></param>
    public void Parse(Object[] vs)
    {
        if (vs == null || vs.Length < 3) return;

        Count = vs[0].ToInt();
        StartId = (vs[1] as IPacket)?.ToStr();
        EndId = (vs[2] as IPacket)?.ToStr();

        var dic = new Dictionary<String, Int32>();
        if (vs.Length >= 4 && vs[3] is Object[] vs2)
        {
            foreach (Object[] vs3 in vs2)
            {
                if (vs3?.Length == 2)
                {
                    var consumer = (vs3[0] as IPacket)?.ToStr();
                    if (!consumer.IsNullOrEmpty())
                    {
                        var count = (vs3[1] as IPacket)?.ToStr().ToInt() ?? 0;
                        dic[consumer] = count;
                    }
                }
            }
        }
        Consumers = dic;
    }
    #endregion
}