using System;
using Aitex.Core.RT.DataCenter;

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

public class DoubleDataPollProvider : DataPollProviderBase<double>, IInterlockLimitDataProvider
{
    public DoubleDataPollProvider(string dataPath) : base(dataPath)
    {
    }

    protected override object HandleGetValue()
    {
        var value = DATA.Poll(DataPath);
        if (value == null)
            throw new NullReferenceException("unable to poll data, null is returned.");

        if (double.TryParse(value.ToString(), out var dValue))
            return dValue;

        throw new InvalidCastException($"the return value {value} is not a number.");
    }
}