/* ==============================================================================
 * 功能描述：SagaCheck  
 * 创 建 者：Garrett
 * 创建日期：2019/6/11 16:09:09
 * ==============================================================================*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Mechanical;
using SAGA.DotNetUtils.Extend;
using ServiceRevitLib.Common;
using SAGA.RevitUtils.Extends;
using ServiceRevitLib.Extend;

namespace ServiceRevitLib.Mode
{
    /// <summary>
    /// SagaCheck
    /// </summary>
    class EquipInSpaceCheck : CheckBase
    {
        public override void Check()
        {
            base.Check();

            #region

            var document = m_Doc;
            var elements = document.GetEqEcElements();
            var rspaces = document.GetSpaces().Where(t => t.IsValidObject).ToList();
            foreach (Element fi in elements)
            {
                var result = GetCheckResult(fi, rspaces);
                Content.Add(result);
            }

            #endregion

        }

        /// <summary>
        /// 获取检测结果
        /// </summary>
        /// <param name="fi"></param>
        /// <returns></returns>
        private EquipInSpaceCheckResult GetCheckResult(Element fi, List<Space> spaces)
        {
            var result = new EquipInSpaceCheckResult();
            result.FamilyName = fi.GetFamilyName();
            result.Id = fi.Id.ToString();
            var space = fi.GetReferenceSpace(spaces);
            if (space != null)
            {
                result.SpaceId = space.Id.ToString();
                result.Result = ResultState.Success;
            }
            else
            {
                result.Result = ResultState.Failure;
                result.ResultMsg = "请检查设备是否在空间中";
            }

            return result;
        }
    }
}
