/*-------------------------------------------------------------------------
 * 功能描述：ParseBase
 * 作者：xulisong
 * 创建时间： 2019/6/13 16:55:35
 * 版本号：v1.0
 *  -------------------------------------------------------------------------*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using JBIM;
using RevitExport;
using RevitExport.Export;
using RevitExport.Parse;
using RevitToJBim.Common;

namespace RevitToJBim.ComponentParse
{
    public abstract class ParseBase : IParseElement<JBimParseContext,BimId>
    {
        #region 接口类相关
        /// <summary>
        /// 快速索引
        /// </summary>
        /// <returns></returns>
        public virtual List<string> FastIndex()
        {
            return new List<string>();//Guid.NewGuid().ToString("N");
        }
        public abstract bool Match(ElementWrapper wrapper);
        public virtual List<ElementWrapper> ArrangeRefElements(ElementWrapper wrapper, JBimParseContext context)
        {
            return null;
        }
        public virtual List<BimId> Parse(ElementWrapper wrapper, JBimParseContext context)
        {
            BimId result = context.GetBimId(wrapper.SourceId);
            if (result != null)
            {
                return new List<BimId>() { result };
            }
            var innerResults = ParseInner(wrapper, context);
            var refElements = ArrangeRefElements(wrapper, context);
            if (refElements != null)
            {
                foreach (var elementWrapper in refElements)
                {
                    try
                    {
                        context.Parser.ParseElement(elementWrapper);
                    }
                    catch (Exception e)
                    {
                        ExceptionUtil.ThrowIfDubug(e);
                    }
                }
            }
            return innerResults;
        }

        #endregion
        protected abstract List<BimId> ParseInner(ElementWrapper wrapper, JBimParseContext context);
    }
}
