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).BinToHex();
            var year = $"{DateTime.Now.ToString("yyyy").Substring(0, 2)}{data[5]}";
            string date= $"{year}-{months.ToString().PadLeft(2, '0')}-{day} {hours}:{minutes}:{seconds}";
            string[] weekdays = {"", "星期一", "星期二", "星期三","星期四", "星期五", "星期六", "星期日"};
            int.TryParse(week, out int weekday);
            // Item1=日期，Item2=星期几
            result?.Invoke(Tuple.Create(date, weekdays[weekday]));
            return await Task.FromResult(true);
        }

     
    }
}
