using WCS.Core;
using WCS.Entity.Protocol.SRM;
using WCS.WorkEngineering.Extensions;
using WCS.WorkEngineering.Worlds;

namespace WCS.WorkEngineering.Systems
{
    /// <summary>
    ///  设备信息写入接口
    /// </summary>
    [BelongTo(typeof(MainWorld))]
    public class SrmDebugSystem : ServiceSystem<SrmDebugInfo>
    {
        private List<SRM> Srms;

        /// <summary>
        ///  构造函数
        /// </summary>
        public SrmDebugSystem()
        {
            Srms = Device.All.Where(v => v.HasProtocol<ISRM520>()).Select(v => new SRM(v, this.World)).ToList();
        }

        protected override void Do(SrmDebugInfo info)
        {
            var srm = Srms.FirstOrDefault(v => v.Entity.Code == info.SrmCode);
            srm.Data.TaskType = info.srmTaskType;
            srm.Data.SLine = info.SLine;
            srm.Data.SCol = info.SCol;
            srm.Data.SLayer = info.SLayer;
            srm.Data.ELine = info.ELine;
            srm.Data.ECol = info.ECol;
            srm.Data.ELayer = info.ELayer;
            srm.Data.VoucherNo++;
        }
    }

    /// <summary>
    /// 设备写入信息
    /// </summary>
    public class SrmDebugInfo
    {
        public string SrmCode { get; set; }

        public SrmTaskTypeEnum srmTaskType { get; set; }

        public short SLine { get; set; }

        public short SCol { get; set; }

        public short SLayer { get; set; }

        public short ELine { get; set; }

        public short ECol { get; set; }

        public short ELayer { get; set; }
    }
}
