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

namespace Models
{
    [SugarIndex("index_{table}_code", nameof(Product.Code), OrderByType.Asc, isUnique: true)]
    public class Product : BaseTable
    {  
        public string Code { get; set; }
        public string Name { get; set; } 
        [SugarColumn(IsNullable = true)]
        public string Spec { get; set; }

        //类别
        public int ClassesId { get; set; }
        [Navigate(NavigateType.ManyToOne, nameof(ClassesId))]
        public Classes ClassesInfo { get; set; }

        //目数
        public int HoleCount { get; set; }

        //外观检测模型文件 //不存在默认使用 .\onnx\default.onnx
        [SugarColumn(IsNullable = true)]
        public string DefectModelFile { get; set; }

        //Files Type0-产品图纸
        [Navigate(NavigateType.OneToMany, nameof(Attachment.Pid))]
        public List<Attachment> AttachmentList { get; set; }//注意禁止给books手动赋值,也不能new初始化，否则导航查询不到

        //当前最新批次号
        public string BatchId { get; set; }
        /// <summary>
        /// 目标数量
        /// </summary>
        public int TargetCount { get; set; }
        /// <summary>
        /// 完成数量
        /// </summary>
        public int CompleteCount { get; set; }
        [Navigate(NavigateType.OneToMany, nameof(BatchHistory.Pid))]
        public List<BatchHistory> BatchHistoryList { get; set; }//注意禁止给books手动赋值,也不能new初始化，否则导航查询不到

        /// <summary>
        /// 合格标准
        /// </summary>
        [Navigate(NavigateType.OneToMany, nameof(QualifiedCriterion.Pid))]
        public List<QualifiedCriterion> QualifiedCriterionList { get; set; }

        [SugarColumn(IsNullable = true)]
        public string Note { get; set; }

        //
        public double TensionBaseValue { get; set; }
        public double TensionUpFloatValue { get; set; }
        public double TensionDownFloatValue { get; set; }
        public double HeightBaseValue { get; set; }
        public double HeightUpFloatValue { get; set; }
        public double HeightDownFloatValue { get; set; }
        public double LineWidthBaseValue { get; set; }
        public double LineWidthUpFloatValue { get; set; }
        public double LineWidthDownFloatValue { get; set; }
        public double PTBaseValue { get; set; }
        public double PTUpFloatValue { get; set; }
        public double PTDownFloatValue { get; set; }

        //高度BASE值
        public string HeightBaseDec { get; set; }

        //====生产流程绑定
        [SugarColumn(IsNullable = true)]
        public int? StepId { get; set; }
        [Navigate(NavigateType.ManyToOne, nameof(StepId))]
        public Step StepInfo { get; set; }
        //流程工序列表
        [Navigate(NavigateType.OneToMany, nameof(ProductProcess.Pid))]
        public List<ProductProcess> ProductProcessList { get; set; }//注意禁止给books手动赋值,也不能new初始化，否则导航查询不到

        //====校正流程绑定
        [SugarColumn(IsNullable = true)]
        public int? ReviseStepId { get; set; }
        [Navigate(NavigateType.ManyToOne, nameof(ReviseStepId))]
        public Step ReviseStepInfo { get; set; }

        //校正流程工序列表
        [Navigate(NavigateType.OneToMany, nameof(ProductReviseProcess.Pid))]
        public List<ProductReviseProcess> ProductReviseProcessList { get; set; }//注意禁止给books手动赋值,也不能new初始化，否则导航查询不到

        //====修复流程绑定
        [SugarColumn(IsNullable = true)]
        public int? AssistStepId { get; set; }
        [Navigate(NavigateType.ManyToOne, nameof(AssistStepId))]
        public Step AssistStepInfo { get; set; }

        //校正流程工序列表
        [Navigate(NavigateType.OneToMany, nameof(ProductAssistProcess.Pid))]
        public List<ProductAssistProcess> ProductAssistProcessList { get; set; }//注意禁止给books手动赋值,也不能new初始化，否则导航查询不到

        //生产记录(用于导航删除)
        [Navigate(NavigateType.OneToMany, nameof(Order.ProductId))]
        public List<Order> OrderList { get; set; }//注意禁止给books手动赋值,也不能new初始化，否则导航查询不到

        //2023-11-2 加入mark使用
        //mark类型 0：无mark
        public int MarkType { get; set; }
        //mark尺寸
        public double MarkSize { get; set; }
        //抓点图像
        [SugarColumn(IsNullable = true)]
        public string MapPath { get; set; }
        //抓取点位
        [SugarColumn(IsNullable = true)]
        public string GetPointList { get; set; }

        //2023-12-18 加入mark干扰判断，是否主栅
        public int MarkDisturb { get; set; }
        public int MainGrid { get; set; }

        //2024-1-24 加入是否存在pad点
        [SugarColumn(IsNullable = true)]
        public int HavePad { get; set; }
    }
    /// <summary>
    /// 结束的批次才加入
    /// </summary>
    public class Attachment : BaseTable
    {
        /// <summary>
        /// 源表名，小写
        /// </summary>
        public string TBName { get; set; }
        /// <summary>
        /// 子类 看TB主表对应类型
        /// </summary>
        public int Type { get; set; } = 0;
        public int Pid { get; set; }
        /// <summary>
        /// 原始文件名还扩展名
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 本地文件名 子路径+文件名(无扩展名)：{TBName}\\{NameTimestamp} //NameTimestamp=id\\A      
        /// </summary>
        public string NameTimestamp { get; set; }
        /// <summary>
        /// .pdf/.doc
        /// </summary>
        public string ExtendName { get; set; }
    }
    /// <summary>
    /// 非全量copy于StepProcess工序，只有产品修改工序参数时保存
    /// </summary> 
    public class ProductProcess : BaseTable
    {
        public int Pid { get; set; }
        public string ProcessCode { get; set; }
        /// <summary>
        /// json
        /// </summary>
        [SugarColumn(IsNullable = true, Length = 2048)]
        public string ProcessParams { get; set; }
    } 
    public class ProductReviseProcess : ProductProcess
    { 
    }
    public class ProductAssistProcess : ProductProcess
    {
    }
    /// <summary>
    /// 结束的批次才加入
    /// </summary>
    public class BatchHistory : BaseTable
    {
        public int Pid { get; set; } 
        public string BatchId { get; set; }
        /// <summary>
        /// 目标数量
        /// </summary>
        public int TargetCount { get; set; }
        /// <summary>
        /// 当前数量
        /// </summary>
        public int CompleteCount { get; set; } 
    }
    /// <summary>
    /// 合格标准
    /// </summary>
    public class QualifiedCriterion : BaseTable
    {
        public int Pid { get; set; } 
        public string DefectCode { get; set; }//pp,sx,...  EnumUtil.Convert2Enum
        /// <summary>
        /// 尺寸
        /// </summary>
        public float Size { get; set; }
        /// <summary>
        /// 最大允许缺陷数量
        /// </summary>
        public int MaxDefectCount { get; set; }
    }

}
