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

namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Aligners.HiWinAligner.Handlers
{
    public class HwAlignerWaferCheckHandler : HwAlignerGuideHandler
    {
        public HwAlignerWaferCheckHandler(HwAlignerGuide device, int timeout = 100)
            : base(device, "DOC")
        {
            AckTimeout = TimeSpan.FromSeconds(timeout);
            CompleteTimeout = TimeSpan.FromSeconds(timeout);
            Name = device.Name;
            device.HaveWafer = false;
            device.SetCurrentOper();
        }

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

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