using Newtonsoft.Json;
using System.Collections.Generic;
using System.Linq;

namespace HTCoreServiceApp.Common
{
    /// <summary>
    /// Json数据整理
    /// </summary>
    public class LiveJsonIntegrate
    {
        /// <summary>
        /// 返回整个Group的value
        /// </summary>
        /// <param name="liveGroupDictionary"></param>
        /// <returns></returns>
        public static string MetaValues2Json(LiveGroupDictionary liveGroupDictionary)
        {
            string res = string.Empty;
            Dictionary<string, string> values = new Dictionary<string, string>(); 
            var MetaTagValues = liveGroupDictionary.MetaTagValues;
            foreach(var metaTagValue in MetaTagValues) 
            {
                values.Add(metaTagValue.TagName, metaTagValue.TagValue);
            }
            res = JsonConvert.SerializeObject(values, Formatting.Indented);
            return res;
        }
        /// <summary>
        /// 返回单个标签value
        /// </summary>
        /// <param name="liveGroupDictionary"></param>
        /// <param name="tagName"></param>
        /// <returns></returns>
        public static string MetaTagValue2Json(LiveGroupDictionary liveGroupDictionary, string tagName)
        {
            string res = string.Empty;
            Dictionary<string, string> values = new Dictionary<string, string>();
            var MetaTagValue = liveGroupDictionary.MetaTagValues.Where(x=>x.TagName == tagName).First();
            
            values.Add(MetaTagValue.TagName, MetaTagValue.TagValue);
            
            res = JsonConvert.SerializeObject(values, Formatting.Indented);
            return res;
        }

    }
}
