using MeterVision.model;
using MeterVision.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MeterVision.db
{
    public class TSingleDetail
    {
        public string SingleDetailId { get; set; }

        public string CreateTime { get; set; }

        public string SrcImage { get; set; }        // SRC_IMAGE
        public int RunFlag { get; set; }            // RUN_FLAG
        public string RunTime { get; set; }         // RUN_TIME
        public string DstImage { get; set; }        // DST_IMAGE
        public int MeterType { get; set; }       // METER_TYPE
        public int DigitCount { get; set; }             // DIGIT_COUNT
        public int PointerCount { get; set; }           // POINTER_COUNT
        public double LastUnit { get; set; }            // LAST_UNIT
        public int ResultType { get; set; }         // RESULT_TYPE
        public long RawValue { get; set; }      // STAND_VALUE
        public long FinalValue { get; set; }     // RESULT_VALUE
        public long CompleteValue { get; set; }
        public int ResultMeter { get; set; }
        public string AiVer { get; set; }           // AI_VER
        public string DebugInfo { get; set; }       // DEBUG_INFO
        public string LogPath { get; set; }         // LOG_PATH
        public string Memo { get; set; }
        public double BrightVal { get; set; }
        public int FlowRate { get; set; }
        public string MeterRegion { get; set; }
        public string FeatureRegion { get; set; }
        public double LastValue { get; set; }
        public string LastTime { get; set; }

        public string DeviceSn { get; set; }
        public string SampleTime { get; set; }

        public TSingleDetail()
        {
            SingleDetailId = string.Empty;
            CreateTime = string.Empty;
            SrcImage = string.Empty;
            RunFlag = 0;
            RunTime = string.Empty;
            DstImage = string.Empty;
            MeterType = 0;
            DigitCount = 0;
            PointerCount = 0;
            LastUnit = 0;
            ResultType = 0;
            RawValue = -1;
            FinalValue = -1;
            AiVer = string.Empty;
            DebugInfo = string.Empty;
            LogPath = string.Empty;
            Memo = string.Empty;
            BrightVal = 1.20;
            MeterRegion = string.Empty;
            FeatureRegion = string.Empty;
            LastValue = 0;
            LastTime = string.Empty;
            ResultMeter = 0;
            DeviceSn = "";
            SampleTime = "";
            CompleteValue = -1;
        }

        public TSingleDetail(SingleDetailItem singleDetail,ResultModel resultModel)
        {
            //SingleDetailId = singleDetail.SingleDetailId;
            //CreateTime = singleDetail.CreateTime;
            //SrcImage = singleDetail.SrcImage;

            ObjectHelper.CopyMatchingFields(singleDetail, this);

            RunFlag = 1;
            RunTime = ThisApp.GetNowTime_yyyyMMddHHmmss();
            DstImage = resultModel.DstImage;
            ResultMeter = resultModel.ResultMeter;
            ResultType = resultModel.ResultType;
            RawValue = (long)resultModel.RawValue;
            FinalValue = (long)resultModel.FinalValue;
            CompleteValue = (long)resultModel.CompleteValue;
            AiVer = resultModel.AiVer;
            LogPath = resultModel.LogPath;


            // 使用 LINQ 进行转换和条件判断，并过滤掉空字符串
            //var formattedBytes = resultModel.DebugInfoBytes.Select(b => b == 88 ? "" : b.ToString())
            //                          .Where(s => !string.IsNullOrEmpty(s));

            // 使用 string.Join 将结果连接成逗号分割的字符串
            //DebugInfo = string.Join(",", formattedBytes);
            //DebugInfo = string.Join(",", resultModel.DebugInfoBytes.Select(b => b.ToString()));  // 默认是十进制


            // 使用 LINQ 进行转换和条件判断
            //var formattedBytes = resultModel.DebugInfoBytes.Select(b => b == 88 ? "" : b.ToString());
            //DebugInfo = string.Join(",", formattedBytes);
            DebugInfo = ThisApp.GetDebugInfos(resultModel.DebugInfoBytes);
        }

        /////////////////////////////////////////////////////////
    }
}
