using System;
using MECF.Framework.Common.Communications;

namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Aligners.HiWinAligner.Handlers
{
    public class HwAlignerGuideSetHandler : HwAlignerGuideHandler
    {
        public HwAlignerGuideSetHandler(HwAlignerGuide device, string name, string command, int timeout = 30)
            : base(device, command)
        {
            AckTimeout = TimeSpan.FromSeconds(timeout);
            CompleteTimeout = TimeSpan.FromSeconds(timeout);
            Name = name;
            device.SetCurrentOper();
        }

        public override bool HandleMessage(MessageBase msg, out bool handled)
        {
            handled = false;
            var result = msg as HwAlignerGuideMessage;
            if (result is { IsResponse: false })
            {
                handled = true;
                return false;
            }


            handled = Device.ParseData(Name, result.Data, out var returnIfo);
            return returnIfo;
        }
    }
}
