using System;

namespace MECF.Framework.Common.Aitex.Core.RT.EMS
{
    /// <summary>
    /// Maintainer内置的维护项
    /// </summary>
    public class MaintainerItem
    {
        #region Constructors

        /// <summary>
        /// 此构造函数无法添加子项，Add函数不可用
        /// </summary>
        public MaintainerItem()
        {

        }

        /// <summary>
        /// 此构造函数用于构造有子项的维护项
        /// </summary>
        public MaintainerItem(string uid, bool enable, DateTime latest,MaintainerItemConfigInfo cinfo)
        {
            _itemInfo.UID = uid;
            _itemInfo.MaintainedDate = latest;
            _itemInfo.Enable = enable;
            _itemInfo.Config = cinfo;
        }
        #endregion

        #region Properties
        MaintainerItemInfo _itemInfo =new();

        /// <summary>
        /// 确认唯一性,RT无法修改
        /// </summary>
        public string UID => _itemInfo.UID;

        public bool Enable => _itemInfo.Enable;

        public bool IsMaintained => _itemInfo.IsMaintained;

        public DateTime MaintainedDate => _itemInfo.MaintainedDate;

        #endregion

        #region Methods

        /// <summary>
        /// 更新项目及子项目的维护时间
        /// </summary>
        public bool Maintained(DateTime date)
        {
            if (Enable)
            {
                _itemInfo.MaintainedDate = date;
                return true;
            }
            return false;
        }

        public bool SetEnable(bool enable)
        {
            _itemInfo.Enable = enable;
            return true;
        }

        public bool CheckMaintained(DateTime date)
        {
            _itemInfo.IsMaintained = MaintainedDate.CompareTo(date) > 0;//晚于起始时间即为已保养
            return IsMaintained;
        }

        public MaintainerItemInfo GetInfo()
        {
            return _itemInfo;
        }

        #endregion


    }
}
