using Hotline.Share.Dtos.FlowEngine.Workflow;
using Hotline.Share.Dtos.Hotspots;
using Hotline.Share.Dtos.Order;
using Hotline.Share.Dtos.Org;
using Hotline.Share.Enums.KnowledgeBase;
using XF.Utility.EnumExtensions;

namespace Hotline.Share.Dtos.Knowledge
{
    public record KnowledgeBaseDataDto
    {
        /// <summary>
        /// 知识ID
        /// </summary>
        public string Id { get; set; }

        /// <summary>
        /// 标题
        /// </summary>
        public string Title { get; set; }

        ///// <summary>
        ///// 知识分类
        ///// </summary>
        //public List<KnowledgeRelationTypeDto> KnowledgeType { get; set; }

        /// <summary>
        /// 知识分类名称
        /// </summary>
        //public string KnowledgeTypeText => GetKnowledgeTypeText(KnowledgeType);
        public string KnowledgeTypeText { get; set; }

        ///// <summary>
        ///// 获取知识分类名称
        ///// </summary>
        ///// <returns></returns>
        //public string GetKnowledgeTypeText(List<KnowledgeRelationTypeDto> items)
        //{

        //	if (KnowledgeType != null && KnowledgeType.Any())
        //	{
        //		var names = KnowledgeType.Select(x => x.KnowledgeTypeName).ToList();
        //		return string.Join(",", names);
        //	}
        //	return "";
        //}


        public HotspotDto HotspotType {  get; set; }

        /// <summary>
        /// 热点
        /// </summary>
        public string HotspotName => HotspotType != null ? HotspotType.HotSpotFullName : string.Empty;

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

        /// <summary>
        /// 浏览量
        /// </summary>
        public int PageView { get; set; }

        /// <summary>
        /// 文档状态
        /// </summary>
        public EKnowledgeStatus Status { get; set; }


        public EKnowledgeStatus NewStatus => Status != EKnowledgeStatus.Drafts && DateTime.Now > ExpiredTime ? EKnowledgeStatus.Overdue : Status;

		/// <summary>
		/// 文档状态名称
		/// </summary>
		public string StatusName => NewStatus.GetDescription();

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


        /// <summary>
        /// 是否公开
        /// </summary>
        public bool IsPublic { get; set; }

        /// <summary>
        /// 过期时间
        /// </summary>
        public DateTime? ExpiredTime { get; set; }
	}

    /// <summary>
    /// 知识库
    /// </summary>
    public record KnowledgeDataDto : KnowledgeBaseDataDto
    {
        /// <summary>
        /// 申请部门
        /// </summary>
        public string CreatorOrgName { get; set; }

        /// <summary>
        /// 申请部门ID
        /// </summary>
        public string CreatorOrgId { get; set; }

        /// <summary>
        /// 是否上架
        /// </summary>
        public bool IsOnShelf { get; set; }

        /// <summary>
        /// 上架时间
        /// </summary>
        public DateTime? OnShelfTime { get; set; }

        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime? LastModificationTime { get; set; }

        /// <summary>
        /// 下架时间
        /// </summary>
        public DateTime? OffShelfTime { get; set; }

        /// <summary>
        /// 申请时间
        /// </summary>
        public DateTime CreationTime { get; set; }

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

        /// <summary>
        /// 知识归属
        /// </summary>
        public string? Attribution { get; set; }

		//public WorkflowDto? Workflow { get; set; }

		/// <summary>
		/// 来源部门
		/// </summary>
		public string? SourceOrganizeId { get; set; }

        /// <summary>
        /// 来源部门
        /// </summary>
        public OrgDto SourceOrganize { get; set; }
    }

    /// <summary>
    /// 审核管理
    /// </summary>
    public record KnowledgeApprovalDataDto : KnowledgeBaseDataDto
    {
        /// <summary>
        /// 申请部门
        /// </summary>
        public string CreateBMName { get; set; }

        /// <summary>
        /// 审核类型
        /// </summary>
        public EKnowledgeApplyType WorkflowModuleStatus { get; set; }

        /// <summary>
        /// 审核类型名称
        /// </summary>
        public string WorkflowModuleStatusName => WorkflowModuleStatus.GetDescription();

        /// <summary>
        /// 审批状态
        /// </summary>
        public EKnowledgeWorkFlowStatus WorkFlowApplyStatus { get; set; }

        /// <summary>
        /// 审核状态名称
        /// </summary>
        public string WorkFlowApplyStatusName => WorkFlowApplyStatus.GetDescription();

        /// <summary>
        /// 到达当前办理节点时间
        /// </summary>
        public DateTime? CurrentStepTime { get; set; }

        /// <summary>
        /// 申请时间
        /// </summary>
        public DateTime CreationTime { get; set; }

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

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

    /// <summary>
    /// 知识检索
    /// </summary>
    public record KnowledgeRetrievalDataDto
    {
        /// <summary>
        /// 知识ID
        /// </summary>
        public string Id { get; set; }

        /// <summary>
        /// 标题
        /// </summary>
        public string Title { get; set; }

        /// <summary>
        /// 摘要
        /// </summary>
        public string Summary { get; set; }

        /// <summary>
        /// 内容
        /// </summary>
        public string Content { get; set; }

        /// <summary>
        /// 评分
        /// </summary>
        public decimal Score { get; set; }

        /// <summary>
        /// 评论数
        /// </summary>
        public int CommentNum { get; set; }

        /// <summary>
        /// 浏览量
        /// </summary>
        public int PageView { get; set; }

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

        public string? CreatorOrgName { get; set; }

        /// <summary>
        /// 来源部门
        /// </summary>
        public OrgDto SourceOrganize { get; set; }

		/// <summary>
		/// 知识分类
		/// </summary>
		public List<KnowledgeRelationTypeDto> KnowledgeType { get; set; }

		/// <summary>
		/// 知识分类名称
		/// </summary>
		public string KnowledgeTypeText => GetKnowledgeTypeText(KnowledgeType);

		/// <summary>
		/// 获取知识分类名称
		/// </summary>
		/// <returns></returns>
		public string GetKnowledgeTypeText(List<KnowledgeRelationTypeDto> items)
		{

			if (KnowledgeType != null && KnowledgeType.Any())
			{
				var names = KnowledgeType.Select(x => x.KnowledgeTypeName).ToList();
				return string.Join(",", names);
			}
			return "";
		}

        /// <summary>
        /// 上架时间
        /// </summary>
        public DateTime? OnShelfTime { get; set; }
    }

    /// <summary>
    /// 获取知识创建部门信息
    /// </summary>
    public record KnowledgeCreateBMDataDto
    {
        /// <summary>
        /// 知识ID
        /// </summary>
        public string Id { get; set; }

        /// <summary>
        /// 知识Code
        /// </summary>
        public string Code { get; set; }

        /// <summary>
        /// 标题
        /// </summary>
        public string Title { get; set; }

        /// <summary>
        /// 处理部门Id
        /// </summary>
        public string DepartmentId { get; set; }

        /// <summary>
        /// 处理部门名称
        /// </summary>
        public string Department { get; set; }
    }

    /// <summary>
    /// 我的申请返回
    /// </summary>
    public record KnowledgeDeleteApplyDataDto : KnowledgeBaseDataDto
    {
        /// <summary>
        /// 申请部门
        /// </summary>
        public string CreationBMName { get; set; }

        /// <summary>
        /// 审批状态
        /// </summary>
        public EKnowledgeWorkFlowStatus WorkFlowApplyStatus { get; set; }

        /// <summary>
        /// 审批状态名称
        /// </summary>
        public string WorkFlowApplyStatusName => WorkFlowApplyStatus.GetDescription();

        /// <summary>
        /// 申请时间
        /// </summary>
        public DateTime CreationTime { get; set; }
    }
}
