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

namespace JiShe.CollectBus.Protocol.T37612012.Appendix
{
    public class Appendix_A1 : IAnalysisStrategy<List<string>>
    {
        private readonly ILogger<Appendix_A1> _logger;

        public Appendix_A1(ILogger<Appendix_A1> logger)
        {
            _logger = logger;
        }

        public async Task<bool> ExecuteAsync(List<string> data, Action<dynamic>? result = null)
        {
            var seconds = data[0];
            var minutes = data[1];
            var hours = data[2];
            var day = data[3];
            string binString = data[4].HexTo4BinZero();
            var months = (binString.Substring(3, 1).BinToDec() * 10) + Convert.ToInt32(binString.Substring(4, 4).BinToHex());
            var week = binString.Substring(0, 3).HexTo4BinZero();
            var year = $"{DateTime.Now.ToString("yyyy").Substring(0, 2)}{data[5]}";
            string date= $"{year}-{months.ToString().PadLeft(2, '0')}-{day} {hours}:{minutes}:{seconds}_{week}";
            result?.Invoke(date);
            return await Task.FromResult(true);
        }

     
    }
}
