using System;

namespace Aitex.Core.RT.IOCore.Interlock.Utils;

public class InterlockLimitRangeShort : IAnalogInterlockLimitRange<short>
{
    #region Constructors
    
    public InterlockLimitRangeShort(string value)
    {
        var strValues = value.Split(':');
        if (strValues.Length == 2
            && short.TryParse(strValues[0], out var min)
            && short.TryParse(strValues[1], out var max))
        {
            Min = min;
            Max = max;
        }
        else
            throw new InvalidCastException($"unable to convert {value} to double range.");
    }

    public InterlockLimitRangeShort(short min, short max)
    {
        Min = min;
        Max = max;
    }

    #endregion

    #region Properties

    public short Min { get; }
    
    public short Max { get; }

    #endregion

    public virtual bool CheckIsInRange(short currentValue)
    {
        return currentValue >= Min && currentValue <= Max;
    }
}