using Hotline.Share.Dtos.File;
using Hotline.Share.Enums.Order;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Hotline.Share.Dtos.FlowEngine.Workflow;
using XF.Utility.EnumExtensions;

namespace Hotline.Share.Dtos.Order
{
    public class OrderScreenDto
    {

        /// <summary>
        /// 工单编号
        /// </summary>
        public string Id { get; set; }

        /// <summary>
        /// 工单编号
        /// </summary>
        public string No { get; set; }

        /// <summary>
        /// 回访id
        /// </summary>
        public string VisitId { get; set; }

        /// <summary>
        /// 回访明细id
        /// </summary>
        public string VisitDetailId { get; set; }

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

        /// <summary>
        /// 甄别申请类型id
        /// </summary>
        public string TypeDicId { get; set; }

        /// <summary>
        /// 甄别申请类型名称
        /// </summary>
        public string TypeDicName { get; set; }


        /// <summary>
        /// 甄别申请原因
        /// </summary>
        public string Content { get; set; }

        /// <summary>
        /// 甄别申请回复
        /// </summary>
        public string? ReplyContent { get; set; }

        /// <summary>
        /// 甄别申请状态
        /// </summary>
        public EScreenStatus? Status { get; set; }

        /// <summary>
        /// 甄别截至申请时间
        /// </summary>
        public DateTime? ApplyEndTime { get; set; }

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

        /// <summary>
        /// 附件列表
        /// </summary>
        public List<FileDto> Files { get; set; } = new();

        public List<FileJson>? FileJson { get; set; }

        /// <summary>
        /// 甄别退回次数
        /// </summary>
        public int SendBackNum { get; set; }

        /// <summary>
        /// 甄别退回到申请人
        /// </summary>
        public bool SendBackApply { get; set; }

        /// <summary>
        /// 甄别重提申请次数
        /// </summary>
        public int SendBackApplyNum { get; set; }

        /// <summary>
        /// 甄别类型
        /// </summary>
        public EOrderScreenType? ScreenType { get; set; }
    }

    public class OrderScreenListDto
    {

        /// <summary>
        /// 甄别类型
        /// </summary>
        public EOrderScreenType? ScreenType { get; set; }

        public string ScreenTypeText => ScreenType.HasValue ? ScreenType.GetDescription() : string.Empty;

        /// <summary>
        /// 是否可办理
        /// </summary>
        public bool IsCanHandle { get; set; }


        /// <summary>
        /// 办理 true  审批 false 
        /// </summary>
        public bool Handle { get; set; }

        /// <summary>
        /// 工单编号
        /// </summary>
        public string No { get; set; }

        /// <summary>
        /// 工单id
        /// </summary>
        public string VisitId { get; set; }

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

        /// <summary>
        /// 回访
        /// </summary>
        public OrderVisitDto Visit { get; set; }

        /// <summary>
        /// 工单
        /// </summary>
        public OrderDto Order { get; set; }


        public WorkflowDto Workflow { get; set; }

        /// <summary>
        /// 甄别明细
        /// </summary>
        public OrderScreenDetailDto ScreenDetail => ScreenDetails != null && ScreenDetails.Any() ? ScreenDetails.First() : null;

        /// <summary>
        /// 甄别明细
        /// </summary>
        public List<OrderScreenDetailDto> ScreenDetails { get; set; }

        /// <summary>
        /// 回访明细id
        /// </summary>
        public string VisitDetailId { get; set; }

        /// <summary>
        /// 回访
        /// </summary>
        public OrderVisitDetailDto VisitDetail { get; set; }

        /// <summary>
        /// 甄别申请类型id
        /// </summary>
        public string? TypeDicId { get; set; }

        /// <summary>
        /// 甄别申请类型名称
        /// </summary>
        public string? TypeDicName { get; set; }


        /// <summary>
        /// 甄别申请原因
        /// </summary>
        public string? Content { get; set; }

        /// <summary>
        /// 甄别申请回复
        /// </summary>
        public string? ReplyContent { get; set; }


        /// <summary>
        /// 甄别截至申请时间
        /// </summary>
        public DateTime? ApplyEndTime { get; set; }

        /// <summary>
        /// 甄别申请状态
        /// </summary>
        public EScreenStatus? Status { get; set; }

        public string StatusText => Status.GetDescription();

        public DateTime? LastModificationTime { get; set; }

        public bool IsDeleted { get; set; }

        /// <summary>
        /// 删除时间
        /// </summary>
        public DateTime? DeletionTime { get; set; }


        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreationTime { get; set; }

        public string Id { get; set; }

        /// <summary>
        /// 组织Id
        /// </summary>
        public string? CreatorOrgId { get; set; }


        public string? CreatorOrgName { get; set; }

        /// <summary>
        /// 创建人
        /// </summary>
        public string? CreatorId { get; set; }

        public string? CreatorName { get; set; }

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

        /// <summary>
        /// 附件
        /// </summary>
        public List<FileJson>? FileJson { get; set; } = new();

        public List<FileDto> Files { get; set; }

		/// <summary>
		/// 附件
		/// </summary>
		public List<FileJson>? ProvinceFileJson { get; set; } = new();

		public List<FileDto> ProvinceFiles { get; set; }

		/// <summary>
		/// 甄别耗时
		/// </summary>
		public decimal? TimeConsuming { get; set; }

        public string TimeConsuminText => TimeConsuming.HasValue ? TimeConsuming.ToString() + "天" : "-";
        /// <summary>
        /// 甄别退回次数
        /// </summary>
        public int SendBackNum { get; set; }

        /// <summary>
        /// 甄别退回到申请人
        /// </summary>
        public bool SendBackApply { get; set; }

        /// <summary>
        /// 甄别退回
        /// </summary>
        public string ScreenSendBack => Status == EScreenStatus.SendBack && SendBackApply ? "是" : "否";

        /// <summary>
        /// 甄别重提申请次数
        /// </summary>
        public int SendBackApplyNum { get; set; }

        /// <summary>
        /// 重提甄别
        /// </summary>
        public string ScreenSendBackApply => SendBackApplyNum > 0 ? "是" : "否";

        /// <summary>
        /// 甄别退回时间
        /// </summary>
        public DateTime? SendBackTime { get; set; }

        /// <summary>
        /// 甄别审批时间
        /// </summary>
        public DateTime? NewestAuditTime { get; set; }
    }

    public class PublishScreenDto
    {
        // <summary>
        /// 工单对象
        /// </summary>
        public OrderDto Order { get; set; }

        /// <summary>
        /// 甄别
        /// </summary>
        public OrderScreenListDto Screen { get; set; }

        /// <summary>
        /// 附件
        /// </summary>
        public string ClientGuid { get; set; }
    }
    public class ProvinceScreenResult
    {
        /// <summary>
        /// 省工单编号
        /// </summary>
        public string CaseSerial { get; set; }

        /// <summary>
        /// 审核结果是否通过
        /// 初审不通过	0	可以再次申请甄别
        ///终审通过	    1	通过办结工单
        ///终审不通过	2	不可以再申请甄别
        /// </summary>
        public string AuditResult { get; set; }

        /// <summary>
        /// 审核意见
        /// </summary>
        public string AuditOpinion { get; set; }

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

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

        /// <summary>
        /// 审核人
        /// </summary>
        public string AuditPerson { get; set; }

        /// <summary>
        /// 行政区划代码
        /// </summary>
        public string AreaCode { get; set; }
    }

    public class OrderScreenEndTimeDto
    {
        /// <summary>
        /// 回访明细id
        /// </summary>
        public string Id { get; set; }

        /// <summary>
        /// 截至甄别时间
        /// </summary>
        public DateTime ScreenByEndTime { get; set; }
    }

    public class OrderScreenAlterDto { 
    
        /// <summary>
        /// 甄别Id
        /// </summary>
        public string ScreenId { get; set; }


		/// <summary>
		/// 甄别申请原因
		/// </summary>
		public string? Content { get; set; }

        /// <summary>
        /// 附件
        /// </summary>
		//public List<FileDto> Files { get; set; }
	}

    public enum EOrderScreenType
    {
        /// <summary>
        /// 部门办件
        /// </summary>
        [Description("部门办件")]
        Org = 0,

        /// <summary>
        /// 中心话务
        /// </summary>
        [Description("中心话务")]
        Seat = 1,
    }
}
