using JiShe.CollectBus.Common.Extensions;
using JiShe.CollectBus.Protocol.Interfaces;

namespace JiShe.CollectBus.Protocol.T37612012.Appendix
{
    public class Appendix_A25 : IAnalysisStrategy<List<string>>
    {
        public async Task<bool> ExecuteAsync(List<string> data, Action<dynamic>? result = null)
        {
            decimal value = 0.000M;
            string binString = string.Empty;
            if (data[0].Check3761Byte())
            {
                binString = data[0].HexTo4BinZero();
                value += (binString.Substring(0, 4).BinToDec() / 100M) + (binString.Substring(4, 4).BinToDec() / 1000M);
            }
            if (data[1].Check3761Byte())
            {
                binString = data[1].HexTo4BinZero();
                value += (binString.Substring(0, 4).BinToDec() / 1M) + (binString.Substring(4, 4).BinToDec() / 10M);
            }
            if (data[2].Check3761Byte())
            {
                binString = data[2].HexTo4BinZero();
                value += (binString.Substring(1, 3).BinToDec() * 100M) + (binString.Substring(4, 4).BinToDec() * 10M);
                int sign = Convert.ToInt32(binString.Substring(0, 1));//正负值标记
                value = sign == 0 ? value * 1 : value * -1;
            }
            result?.Invoke(value);
            return await Task.FromResult(true);
        }

    }
}
