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

namespace JiShe.CollectBus.Protocol.T37612012.Appendix
{
    /// <summary>
    /// 第一套时区表数据
    /// </summary>
    public class Appendix_04010000 : IAnalysisStrategy<List<string>>
    {
        /// <summary>
        /// 每个值字节数
        /// </summary>
        private const int valueByteCount = 3;
        private readonly ILogger<Appendix_04010000> _logger;

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

        public async Task<bool> ExecuteAsync(List<string> data, Action<dynamic>? result = null)
        {
            List<string> values = new List<string>();
            int valueCount = data.Count / valueByteCount;
            values.Insert(0, "10_94");
            values.Insert(0, "第一套第{0}时区起始日期及日时段表号");
            values.Add(valueCount.ToString());//值总数 11 11 11 22 22 22 33 33 33
            for (int i = 0; i < valueCount; i++)
            {
                var value = data.GetRange(i * 3, valueByteCount);//MMDDNN
                values.Add($"{value[0]}:{value[1]}");//MM:DD 或hhmm
                values.Add(value[2]);//NN 费率号
            }
            result?.Invoke(values);
            return await Task.FromResult(true);
        }
    }
}
