using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Models
{
    [SugarIndex("index_{table}_sn", nameof(Order.SN), OrderByType.Asc, isUnique: true)]
    public class Order : BaseTable
    {
        /// <summary>
        /// 产品
        /// </summary>
        public int ProductId { get; set; }
        [Navigate(NavigateType.ManyToOne, nameof(ProductId))]
        public Product ProductInfo { get; set; }

        public string SN { get; set; }
        public string BatchId { get; set; }
        /// <summary>
        /// 流程
        /// </summary>
        public int StepId { get; set; }
        [Navigate(NavigateType.ManyToOne, nameof(StepId))]
        public Step StepInfo { get; set; }

        /// <summary>
        /// 时长-秒
        /// </summary>
        public double TimeLen { get; set; }
        /// <summary>
        /// 是否合格
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public bool Qualified { get; set; } = true;

        /// <summary>
        /// 比对结果 0-未比对 1-通过 2-不通过
        /// </summary>
        public int CompareResult { get; set; } = 0;


        //平均值
        public double TensionValue { get; set; }
        public double HeightValue { get; set; }
        public double LineWidthValue { get; set; }
        public double PTValue { get; set; }

        //N次
        #region 张力5次
        public double Tension1 { get; set; }
        public double Tension2 { get; set; }
        public double Tension3 { get; set; }
        public double Tension4 { get; set; }
        public double Tension5 { get; set; }
        #endregion
        #region 厚度5次
        public double Height1 { get; set; }
        public double Height2 { get; set; }
        public double Height3 { get; set; }
        public double Height4 { get; set; }
        public double Height5 { get; set; }
        #endregion
        #region 线宽9次
        public double LineWidth1 { get; set; }
        public double LineWidth2 { get; set; }
        public double LineWidth3 { get; set; }
        public double LineWidth4 { get; set; }
        public double LineWidth5 { get; set; }
        public double LineWidth6 { get; set; }
        public double LineWidth7 { get; set; }
        public double LineWidth8 { get; set; }
        public double LineWidth9 { get; set; }
        #endregion 
        #region PT6次
        public double PT1 { get; set; }
        public double PT2 { get; set; }
        public double PT3 { get; set; }
        public double PT4 { get; set; }
        public double PT5 { get; set; }
        public double PT6 { get; set; }
        #endregion
        /// <summary>
        /// 缺陷数
        /// </summary>
        public int DefectCount { get; set; }

        #region 缺陷种类
        public int DKCount { get; set; }//堵孔数量
        public int ZWCount { get; set; }//脏污数量
        public int GSYCCount { get; set; }//钢丝异常数量
        public int XWSCount { get; set; }//纤维丝数量
        public int QKCount { get; set; }//缺口数量
        public int ZKCount { get; set; }//针孔数量
        public int PPCount { get; set; }//泡泡数量
        public int HSCount { get; set; }//划伤数量
        public int YXCount { get; set; }//压线数量 
        public int XBCount { get; set; }//斜边数量 new
        public int SXCount { get; set; }//栅线数量 new
        #endregion

        /// <summary>
        /// mark点数据:[X1,Y1,X2,Y2,X3,Y3,X4,Y4]
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public string MarkData { get; set; }
        //
        public bool Succeed { get; set; }
        /// <summary>
        /// 失败分类
        /// </summary>
        public int FailType { get; set; }
        /// <summary>
        /// 失败的工序名称
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public string FailProcessName { get; set; }
        [SugarColumn(IsNullable = true, ColumnDataType = "text", Length = 2048)]
        public string Note { get; set; }

        /// <summary>
        /// 0-初始; 5-已检测; 10-出现异常
        /// </summary>
        public int State { get; set; }

        //----------
        /// <summary>
        /// 修改次数
        /// </summary>
        public int HistoryCount { get; set; } = 0;
        /// <summary>
        /// 修改历史记录
        /// </summary>
        [Navigate(NavigateType.OneToMany, nameof(OrderHistory.Pid))]
        public List<OrderHistory> OrderHistoryList { get; set; }

        /// <summary>
        /// Defect和Size比对失败的坐标位置
        /// </summary>
        [Navigate(NavigateType.OneToMany, nameof(DefectInfo.Pid))]
        public List<DefectInfo> DefectInfoList { get; set; }

        //-------IsIgnore = true  不保存
        [SugarColumn(IsIgnore = true)]
        //[Navigate(NavigateType.OneToMany, nameof(SizeTagData.Pid))]
        public List<SizeTagData> SizeTagDataList { get; set; }

        //2023-10-30 添加异常列
        /// <summary>
        /// 异常情况
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public string Abnormalities { get; set; }
        /// <summary>
        /// 修复人员
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public string RepairCode { get; set; }
    }
    [SugarIndex("index_{table}_pid", nameof(OrderHistory.Pid), OrderByType.Asc, isUnique: false)]
    public class OrderHistory : BaseTable
    {
        public int Pid { get; set; }
        public bool Qualified { get; set; }//合格

        //比对 
        public int CompareResult { get; set; }
        //平均值
        public double TensionValue { get; set; }
        public double HeightValue { get; set; }
        public double LineWidthValue { get; set; }
        public double PTValue { get; set; }

        //外观
        public int DKCount { get; set; }//堵孔数量
        public int ZWCount { get; set; }//脏污数量
        public int GSYCCount { get; set; }//钢丝异常数量
        public int XWSCount { get; set; }//纤维丝数量
        public int QKCount { get; set; }//缺口数量
        public int ZKCount { get; set; }//针孔数量
        public int PPCount { get; set; }//泡泡数量
        public int HSCount { get; set; }//划伤数量
        public int YXCount { get; set; }//压线数量 
        public int XBCount { get; set; }//斜边数量 new
        public int SXCount { get; set; }//栅线数量 new
    }
     
    [SugarIndex("index_{table}_pid", nameof(SizeTagData.Pid), OrderByType.Asc, isUnique: false)]
    public class SizeTagData : BaseTable
    {
        public int Pid { get; set; }
        public string SizeTag { get; set; }
        /// <summary>
        /// 产生Tag工序索引
        /// </summary>
        public int CreateStepIndex { get; set; }
        /// <summary>
        /// 消费本数据工序索引和消费值索引：5-0,8-2 
        /// </summary>
        public string ConsumeStepIndex { get; set; }

        /// <summary>
        /// double[]
        /// </summary>
        public string posePT { get; set; } 
    }

    [SugarIndex("index_{table}_pid", nameof(DefectInfo.Pid), OrderByType.Asc, isUnique: false)]
    public class DefectInfo : BaseTable
    {
        public int Pid { get; set; }
        /// <summary>
        /// 0-Defect 1-Size
        /// </summary>
        public int Type { get; set; }
        public string Code { get;set; }

        public double X { get; set; } 
        public double Y { get; set; } 
        public double ZXD { get; set; } 
    }
}