using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ewide.Core.Extension.DataFilter.Entity
{
    public class FilterInfo
    {
		/// <summary>
		/// 查询信息集合
		/// </summary>
		private List<SearchInfo> _SearchInfos;

		/// <summary>
		/// 高级查询信息集合
		/// </summary>
		public List<SearchInfo> SearchInfos
		{
			get { return _SearchInfos; }
		}

		public FilterInfo()
		{
			_SearchInfos = new List<SearchInfo>();
		}

		/// <summary>
		/// 设置查询信息
		/// </summary>
		/// <param name="filterFields"></param>
		public void SetSearchInfo(SearchInfo[] searchInfo, IEnumerable<string> filterFields)
		{
			if (searchInfo == null) return;
			try
			{
				foreach (var elem in searchInfo)
				{
					var fieldName = elem.Field;

					if (filterFields.FirstOrDefault(m => m.Equals(fieldName, StringComparison.OrdinalIgnoreCase)) == null) continue;

					var searchStrs = elem.Value;
					if (searchStrs == null) continue;
					if (searchStrs.Count == 0) continue;

					var searchInfoEntity = new SearchInfo();
					searchInfoEntity.Field = fieldName;
					searchInfoEntity.Type = elem.Type;
					var searchStrsNode = elem.Value;
					if (searchStrsNode != null)
					{
                        foreach (var node in searchStrsNode)
                        {
							searchInfoEntity.Value.Add(node);
                        }
                    }
					_SearchInfos.Add(searchInfoEntity);
				}
			}
			catch
			{
			}
		}
	}
}
