using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;

namespace DeviceRepair.Models
{
    /// <summary>
    /// 设备维修申请单
    ///</summary>
    [SugarTable("DeviceWarrantyRequestForm")]
    public class DeviceWarrantyRequestForm : ModelContext
    {
        /// <summary>
        /// 主键编号 (原则：300000000 - 399999999)
        ///</summary>
        [SugarColumn(ColumnName = "AutoID", IsPrimaryKey = true, IsIdentity = true)]
        public int AutoID { get; set; }
        /// <summary>
        /// 唯一编号 
        ///</summary>
        [SugarColumn(ColumnName = "GUID")]
        public Guid GUID { get; set; }
        /// <summary>
        /// 设备表主键编号 
        ///</summary>
        [SugarColumn(ColumnName = "EquipmentPK")]
        public int EquipmentPK { get; set; }
        /// <summary>
        /// 设备编号 
        ///</summary>
        [SugarColumn(ColumnName = "EquipmentID", Length = 50)]
        public string EquipmentID { get; set; }
        /// <summary>
        /// 设备名称 
        ///</summary>
        [SugarColumn(ColumnName = "EquipmentName", Length = 200, ColumnDataType = "nvarchar")]
        public string EquipmentName { get; set; }
        /// <summary>
        /// 发生地点 
        ///</summary>
        [SugarColumn(ColumnName = "Location")]
        public int Location { get; set; }
        /// <summary>
        /// 发生地点 
        ///</summary>
        [SugarColumn(ColumnName = "LocationName")]
        public string LocationName { get; set; }
        /// <summary>
        /// 是否有在途生产单 
        ///</summary>
        [SugarColumn(ColumnName = "InProduction")]
        public bool InProduction { get; set; }
        /// <summary>
        /// 批次号 
        ///</summary>
        [SugarColumn(ColumnName = "Batch", Length = 30)]
        public string Batch { get; set; }
        /// <summary>
        /// 故障现象
        /// </summary>
        [SugarColumn(ColumnName = "FaultSymptoms")]
        public string FaultSymptoms { get; set; }
        /// <summary>
        /// 设备设施部
        /// </summary>
        [SugarColumn(ColumnName = "ReceivingDep")]
        public string ReceivingDep { get; set; }
        /// <summary>
        /// 停机状态（是、否）
        /// </summary>
        [SugarColumn(ColumnName = "IsDown")]
        public bool IsDown { get; set; }
        /// <summary>
        /// 文档版本
        /// </summary>
        [SugarColumn(ColumnName = "FormVer")]
        public int FormVer { get; set; }
        /// <summary>
        /// 申请时间 
        ///</summary>
        [SugarColumn(ColumnName = "CreatOn")]
        public DateTime? CreatOn { get; set; }
        /// <summary>
        /// 申请人 
        ///</summary>
        [SugarColumn(ColumnName = "CreatBy")]
        public int? CreatBy { get; set; }
        /// <summary>
        /// 申请人姓名
        /// </summary>
        [SugarColumn(ColumnName = "CreatorName")]
        public string CreatorName { get; set; }
        /// <summary>
        /// 修改时间 
        ///</summary>
        [SugarColumn(ColumnName = "ModifyOn")]
        public DateTime? ModifyOn { get; set; }
        /// <summary>
        /// 修改人 
        ///</summary>
        [SugarColumn(ColumnName = "ModifyBy")]
        public int? ModifyBy { get; set; }
        /// <summary>
        /// 修改人姓名
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public string ModifyByName { get; set; }

        [SugarColumn(ColumnName = "RestorationConfirmationOn")]
        public DateTime? RestorationConfirmationOn { get; set; }

        [SugarColumn(ColumnName = "RestorationConfirmationBy")]
        public int RestorationConfirmationBy { get; set; }

        [SugarColumn(ColumnName = "RestorationConfirmationOnName")]
        public string RestorationConfirmationOnName { get; set; }


        #region 修改的字段

        //[SugarColumn(IsIgnore = true)]
        //public DeviceWarrantyRequestMaintaionInfo MaintaionInfo { get; set; }

        //[SugarColumn(IsIgnore = true)]
        //public DeviceWarrantyRequestFormStatus FormStatus
        //{
        //    get
        //    {
        //        if (MaintaionInfo == null || MaintaionInfo.SubmitBy == 0)
        //        {
        //            return DeviceWarrantyRequestFormStatus.AwaitingRepair;
        //        }
        //        else if (MaintaionInfo.SubmitBy > 0)
        //        {
        //            return DeviceWarrantyRequestFormStatus.AwaitingApproval;
        //        }
        //        else if (MaintaionInfo.ValidateBy > 0)
        //        {
        //            return DeviceWarrantyRequestFormStatus.BeComplate;
        //        }
        //        return DeviceWarrantyRequestFormStatus.AwaitingRepair;
        //    }
        //}

        //[SugarColumn(IsIgnore = true)]
        //public string FormStatusText
        //{
        //    get
        //    {
        //        return FormStatus.ToDescription();
        //    }
        //}

        //[SugarColumn(IsIgnore = true)]
        //public string IsDownStatusText { get { return IsDown ? "停机" : "非停机"; } }

        ///// <summary>
        ///// 质量部评估人 
        /////</summary>
        //[SugarColumn(ColumnName = "EvaluatorCode_QA")]
        //public Guid? EvaluatorcodeQa { get; set; }
        ///// <summary>
        ///// 质量部评估人姓名 
        /////</summary>
        //[SugarColumn(ColumnName = "EvaluatorName_QA")]
        //public string EvaluatornameQa { get; set; }
        ///// <summary>
        ///// 质量部评估时间 
        /////</summary>
        //[SugarColumn(ColumnName = "EvaluatorOn_QA")]
        //public DateTime? EvaluatoronQa { get; set; }
        ///// <summary>
        ///// 工程部评估人 
        /////</summary>
        //[SugarColumn(ColumnName = "EvaluatorCode_EA")]
        //public Guid? EvaluatorcodeEa { get; set; }
        ///// <summary>
        ///// 工程部评估人姓名 
        /////</summary>
        //[SugarColumn(ColumnName = "EvaluatorName_EA")]
        //public string EvaluatornameEa { get; set; }
        ///// <summary>
        ///// 工程部评估时间 
        /////</summary>
        //[SugarColumn(ColumnName = "EvaluatorOn_EA")]
        //public DateTime? EvaluatoronEa { get; set; }
        ///// <summary>
        ///// 微生物实验室评估人 
        /////</summary>
        //[SugarColumn(ColumnName = "EvaluatorCode_MT")]
        //public Guid? EvaluatorcodeMt { get; set; }
        ///// <summary>
        ///// 微生物实验室评估人姓名 
        /////</summary>
        //[SugarColumn(ColumnName = "EvaluatorName_MT")]
        //public string EvaluatornameMt { get; set; }
        ///// <summary>
        ///// 微生物实验室评估时间 
        /////</summary>
        //[SugarColumn(ColumnName = "EvaluatorOn_MT")]
        //public DateTime? EvaluatoronMt { get; set; }
        ///// <summary>
        ///// 力学实验室评估人 
        /////</summary>
        //[SugarColumn(ColumnName = "EvaluatorCode_TL")]
        //public Guid? EvaluatorcodeTl { get; set; }
        ///// <summary>
        ///// 力学实验室评估人姓名 
        /////</summary>
        //[SugarColumn(ColumnName = "EvaluatorName_TL")]
        //public string EvaluatornameTl { get; set; }
        ///// <summary>
        ///// 力学实验室评估时间 
        /////</summary>
        //[SugarColumn(ColumnName = "EvaluatorOn_TL")]
        //public DateTime? EvaluatoronTl { get; set; }

        #endregion

        [SugarColumn(IsIgnore = true, IsJson = true)]
        public DeviceWarrantyRequestMaintaionInfo MaintaionItems
        {
            get
            {
                return base.CreateMapping<DeviceWarrantyRequestMaintaionInfo>().Where(x => x.FormID == this.AutoID).First();
            }
        }

        [SugarColumn(IsIgnore = true, IsJson = true)]
        public List<DeviceWarrantyEvaluatorInfo> EvaluatorItems
        {
            get
            {
                return base.CreateMapping<DeviceWarrantyEvaluatorInfo>().Where(x => x.FormID == this.AutoID).ToList();
            }
        }
    }
}
