using MECF.Framework.Common.Communications;

namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Temps
{
    public abstract class StrongTempHandler : HandlerBase
    {
        public StrongTemp Device { get; }

        protected StrongTempHandler(StrongTemp device, byte[] commandvalue) : base(commandvalue)
        {
            Device = device;
        }

    }

    public class StrongTempQueryHandler : StrongTempHandler
    {
        public StrongTempQueryHandler(StrongTemp device, string name, byte[] commandvalue)
            : base(device, commandvalue)
        {
            Name = name;//"Query Temp";
        }

        public override bool HandleMessage(MessageBase msg, out bool handled)
        {
            var result = msg as BinaryMessage;
            handled = false;
            if (result.IsError)
            {
                Device.ResponseError();
                return false;
            }
            if (!result.IsComplete)
            {
                return false;
            }

            Device.ResponseQuery(Name, result.RawMessage);
            return true;
        }
    }
}
