namespace SHH.MjpegPlayer
{
    /// <summary>
    /// 会话信息
    /// </summary>
    public class SessionInfo
    {
        #region Key

        /// <summary>流标识</summary>
        public string? Key => $"{DeviceId}#{TypeCode}";

        #endregion

        #region DeviceId

        /// <summary>设备类型</summary>
        public string? DeviceId { get; set; }

        #endregion

        #region TypeCode

        /// <summary>类型编码</summary>
        public string? TypeCode { get; set; }

        #endregion

        #region ClientIp

        /// <summary>客户端 IP</summary>
        public string? ClientIp { get; set; }

        #endregion

        #region ClientPort

        /// <summary>客户端端口</summary>
        public int ClientPort { get; set; }

        #endregion

        #region Message

        /// <summary>消息</summary>
        public string? Message { get; set; }

        #endregion

        #region AcceptTime

        /// <summary>接入时间</summary>
        public DateTime AcceptTime { get; set; }

        #endregion

        #region Counter

        /// <summary>计数器</summary>
        public SumByTime? Counter { get; init; }

        #endregion

        // =======================================================
        // [新增] 专门给诊断大屏用的属性，前端可直接读取数值
        // =======================================================

        /// <summary>接收帧率 (源头健康度)</summary>
        public int RecvFps
        {
            get
            {
                if (Counter == null || Counter.TotalSecond == null) return 0;

                // 从字典中安全获取 "接收帧数"
                if (Counter.TotalSecond.TryGetValue("接收帧数", out uint val))
                {
                    return (int)val;
                }
                return 0;
            }
        }

        /// <summary>播放/发送帧率 (客户端健康度)</summary>
        public int PlayFps
        {
            get
            {
                if (Counter == null || Counter.TotalSecond == null) return 0;

                // 从字典中安全获取 "播放帧数"
                if (Counter.TotalSecond.TryGetValue("播放帧数", out uint val))
                {
                    return (int)val;
                }
                return 0;
            }
        }
    }
}