using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Hotline.FlowEngine.Workflows;
using Hotline.Share.Dtos;
using Hotline.Share.Dtos.File;
using Hotline.Share.Dtos.FlowEngine;
using Hotline.Share.Dtos.FlowEngine.Workflow;
using Hotline.Share.Dtos.Order;
using Hotline.Share.Enums.FlowEngine;
using Hotline.Share.Enums.Order;
using Hotline.Share.Enums.Settings;
using SqlSugar;
using XF.Domain.Repository;

namespace Hotline.Orders
{
	/// <summary>
	/// 特提
	/// </summary>
	[Description("工单特提")]
	[SugarIndex("index_special_orderId", nameof(OrderSpecial.OrderId), OrderByType.Asc)]
	public class OrderSpecial : FullStateEntity
	{
        public string OrderId { get; set; }
        public string WorkflowId { get; set; }

        /// <summary>
        /// 下一节点code(defineStep.code)
        /// </summary>
        public string NextStepCode { get; set; } = string.Empty;
        public string NextStepName { get; set; } = string.Empty;

        public EFlowDirection? FlowDirection { get; set; }

        /// <summary>
        /// 办理对象类型
        /// </summary>
        public EHandlerType? HandlerType { get; set; }
        /// <summary>
        /// 模板配置节点业务类型
        /// </summary>
        public EBusinessType? BusinessType { get; set; }

        /// <summary>
        /// 节点类型
        /// </summary>
        public EStepType? StepType { get; set; }

        /// <summary>
        /// 工单状态
        /// </summary>
        public EOrderStatus? Status { get; set; }

		public string? StepCode { get; set; } = string.Empty;
        public string? StepName { get; set; } = string.Empty;

		[SugarColumn(ColumnDataType = "json", IsJson = true, IsNullable = true)]
		public List<StepAssignInfo> NextHandlers { get; set; }

		/// <summary>
		/// 特提原因
		/// </summary>
		[SugarColumn(ColumnDescription = "特提原因")]
        public string? Cause { get; set; }

		/// <summary>
		/// 特提理由
		/// </summary>
		[SugarColumn(ColumnDescription = "特提理由", ColumnDataType = "text")]
        public string? Reason { get; set; }

        /// <summary>
        /// 办理时间限制(如：24小时、7个工作日)
        /// </summary>
        public int? TimeLimit { get; set; }

        public ETimeType? TimeLimitUnit { get; set; } = ETimeType.WorkDay;

        /// <summary>
        /// 是否修改期满时间
        /// </summary>
        public bool AlterTime { get; set; }

		/// <summary>
		/// 特提意见
		/// </summary>
		[SugarColumn(ColumnDescription = "特提意见", ColumnDataType = "text")]
        public string? Opinion { get; set; }

		/// <summary>
		///  审核结果  0  待审核  1 审核通过  2 审核不通过
		/// </summary>
		public int State { get; set; }

		[SugarColumn(ColumnDescription = "组织Id")]
		public string? OrgId { get; set; }

		public string? OrgName { get; set; }

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

        [SugarColumn(ColumnDataType = "json", IsJson = true, IsNullable = true)]
        public List<FileJson>? ReplyFileJson { get; set; }

        /// <summary>
        /// 特提类型
        /// </summary>
        public ESpecialType? SpecialType { get; set; }

		/// <summary>
		/// 错件类型
		/// </summary>
		//[SugarColumn(ColumnDataType = "json", IsJson = true, IsNullable = true)]
		[Navigate(NavigateType.OneToMany, nameof(OrderSpecialDetail.SpecialId))]
		public List<OrderSpecialDetail> ReTransactError { get; set; }

		/// <summary>
		/// 首次归档意见
		/// </summary>
		[SugarColumn(ColumnDataType = "varchar(8000)")]
		public string? FirstFileOpinion { get; set; }

		/// <summary>
		/// 上次归档意见
		/// </summary>
		[SugarColumn(ColumnDataType = "varchar(8000)")]
		public string? LastFileOpinion { get; set; }

        /// <summary>
        ///特提后最新节点Id
        /// </summary>
        [SugarColumn(ColumnDescription = "特提后最新节点Id")]
        public string? NewCurrentStepId { get; set; }

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

    //public class ReTransactError { 
    
    //    public string OrgId { get; set; }

    //    public string OrgName { get; set; }

    //    public string ErrorId { get; set; }

    //    public string ErrorName { get; set; }
    //}
}
