using System.ComponentModel;
using Hotline.FlowEngine.Workflows;
using Hotline.Share.Dtos.File;
using Hotline.Share.Enums.Order;
using Hotline.Share.Enums.Settings;
using Hotline.Users;
using SqlSugar;
using XF.Domain.Repository;

namespace Hotline.Orders
{
    /// <summary>
    /// 工单延期
    /// </summary>
    [Description("工单延期")]
    [SugarIndex("index_delay_orderId", nameof(OrderDelay.OrderId), OrderByType.Asc)]
	public class OrderDelay : WorkflowEntity
    {
        /// <summary>
        /// 工单编号（冗余）
        /// </summary>
        public string No { get; set; }

        /// <summary>
        /// 工单ID
        /// </summary>
        public string OrderId { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [Navigate(NavigateType.OneToOne, nameof(OrderId))]
        public Order? Order { get; set; }

        /// <summary>
        /// 延期申请时间
        /// </summary>
        public DateTime ApplyDelayTime { get; set; }

        /// <summary>
        /// 申请部门Code
        /// </summary>
        public string ApplyOrgCode { get; set; }

        /// <summary>
        /// 申请部门名称
        /// </summary>
        public string ApplyOrgName { get; set; }

        /// <summary>
        /// 申请人
        /// </summary>
        public string EmployeeId { get; set; }

        /// <summary>
        /// 申请人名称
        /// </summary>
        public string? EmployeeName { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [Navigate(NavigateType.OneToOne, nameof(EmployeeId))]
        public User? Employee { get; set; }

        /// <summary>
        /// 延期申请时限
        /// </summary>
        public int DelayNum { get; set; }

        /// <summary>
        /// 延期申请单位
        /// </summary>
        public ETimeType DelayUnit { get; set; }

		/// <summary>
		/// 延期申请理由
		/// </summary>
		[SugarColumn(ColumnDescription = "延期申请理由", ColumnDataType = "text")]
		public string DelayReason { get; set; }

        /// <summary>
        /// 申请前期满时间
        /// </summary>
        public DateTime? BeforeDelay { get; set; }

        /// <summary>
        /// 申请后期满时间
        /// </summary>
        public DateTime? AfterDelay { get; set; }

        /// <summary>
        /// 审批状态
        /// </summary>
        public EDelayState DelayState { get; set; }

        #region 用于省平台查询
        /// <summary>
        /// 审核人
        /// </summary>
        public string? AuditName { get; set; }

        /// <summary>
        /// 审核部门
        /// </summary>
        public string? AuditOrgName { get; set; }

        /// <summary>
        /// 审核时间
        /// </summary>
        public DateTime? AuditTime { get; set; }

        /// <summary>
        /// 审核意见
        /// </summary>
        [SugarColumn(ColumnDescription = "审核意见", ColumnDataType = "text")]
        public string? AuditOpinion { get; set; } 
        #endregion

        /// <summary>
        /// 审批类型
        /// </summary>
        public EDelayApplyType? DelayApplyType { get; set; }

        /// <summary>
        /// 附件
        /// </summary>
        [SugarColumn(ColumnDataType = "json", IsJson = true, IsNullable = true)]
        public List<FileJson> FileJson { get; set; }

        /// <summary>
        /// 是否省延期
        /// </summary>
        [SugarColumn(DefaultValue = "f")]
        public bool IsProDelay { get; set; }

        /// <summary>
        /// 流程ID
        /// </summary>
        public string? WorkflowId { get; set; }

        [Navigate(NavigateType.OneToOne, nameof(WorkflowId))]
        public Workflow? Workflow { get; set; }

		/// <summary>
		/// 自动延期次数
		/// </summary>
		[SugarColumn(DefaultValue = "0")]
		public int? AutomaticDelayNum { get; set; }


        [Navigate(NavigateType.OneToMany, nameof(WorkflowStep.ExternalId))]
        public List<WorkflowStep> WorkflowSteps { get; set; }

    }
}
