using Hotline.Share.Dtos.CallCenter;
using Hotline.Share.Dtos.File;
using Hotline.Share.Dtos.FlowEngine;
using Hotline.Share.Dtos.Org;
using Hotline.Share.Dtos.Quality;
using Hotline.Share.Enums.Article;
using Hotline.Share.Enums.KnowledgeBase;
using Hotline.Share.Notifications.NewRockCallCenter;
using Hotline.Share.Requests;
using System.ComponentModel.DataAnnotations;
using Hotline.Share.Dtos.FlowEngine.Workflow;
using XF.Utility.EnumExtensions;

namespace Hotline.Share.Dtos.Knowledge
{
    public class UpdateKnowledgeAndApproveDto : UpdateKnowledgeDto
    {
        /// <summary>
        /// 更新意见
        /// </summary>
        public string Opinion { get; set; }
    }

    public class UpdateKnowledgeAndApproveBatchDto : AddKnowledgeDto
    {
        /// <summary>
        /// 更新意见
        /// </summary>
        public string Opinion { get; set; }

        /// <summary>
        /// 知识库ID
        /// </summary>

        public List<string> KnowledgeIds { get; set; }
    }

    /// <summary>
    /// 编辑
    /// </summary>
    public class UpdateKnowledgeDto : AddKnowledgeDto
    {
        /// <summary>
        /// ID
        /// </summary>
        public string Id { get; set; }
    }

    /// <summary>
    /// 新增知识
    /// </summary>
    public class AddKnowledgeDto
    {
        /// <summary>
        /// 知识Code
        /// </summary>
        public string Code { get; set; }

        /// <summary>
        /// 知识来源
        /// </summary>
        public string? Source { get; set; }

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

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

        /// <summary>
        /// 知识归属
        /// </summary>
        public List<string> KnowledgeOrg { get; set; }

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

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

        /// <summary>
        /// 热点
        /// </summary>
        public string HotspotId { get; set; }

        /// <summary>
        /// 外部数据（为前端提供级联功能）
        /// </summary>
        public string HotspotExternal { get; set; }

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

        /// <summary>
        /// 关键词
        /// </summary>
        public List<string> Keywords { get; set; }

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

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

        /// <summary>
        /// 文档号
        /// </summary>
        public string? DocumentNo { get; set; }

        /// <summary>
        /// 版本说明
        /// </summary>
        public string? VersionDescription { get; set; }

        /// <summary>
        /// 索引号
        /// </summary>
        public string? IndexNo { get; set; }

        /// <summary>
        /// 文号
        /// </summary>
        public string? FileNo { get; set; }

        /// <summary>
        /// 预案分类id
        /// </summary>
        public string PlanTypeId { get; set; }

    }

    public record KnowledgeRelationTypeDto
    {


        /// <summary>
        /// 知识库类型ID
        /// </summary>
        public string KnowledgeTypeId { get; set; }

        /// <summary>
        /// 知识库类型名称
        /// </summary>
        public string KnowledgeTypeName { get; set; }


        /// <summary>
        /// 知识库类型名称
        /// </summary>
        public string KnowledgeTypeSpliceName { get; set; }
    }

    public record KnowledgeRelationOrgDto
    {
        public string OrgId { get; set; }
    }

    /// <summary>
    /// 基础
    /// </summary>
    public class KnowledgeDto : UpdateKnowledgeDto
    {
        /// <summary>
        /// 来源部门
        /// </summary>
        public string? SourceOrganizeId { get; set; }

        /// <summary>
        /// 知识分类名称
        /// </summary>
        public string KnowledgeTypeText { get; set; }

        /// <summary>
        /// 标签名称
        /// </summary>
        public List<string> Tags { get; set; } = new();

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

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

        public string StatusText => Status.GetDescription();

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

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

        /// <summary>
        /// 搜索量
        /// </summary>
        public int? SearchNum { get; set; } = 0;

        /// <summary>
        /// 评分
        /// </summary>
        public decimal? Score { get; set; } = decimal.Zero;

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

        public DateTime? LastModificationTime { get; set; }

        /// <summary>
        /// 热点名称
        /// </summary>
        public string HotspotName { get; set; }

        public bool IsDeleted { get; set; }

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


        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreationTime { 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>
        /// 来源部门
        /// </summary>
        public OrgDto? SourceOrganize { get; set; }

        public KnowledgeCollectDto Collect { get; set; }

        /// <summary>
        /// 关联知识
        /// </summary>
        public List<string> Knowledges { get; set; }

        /// <summary>
        /// 关联知识对象
        /// </summary>
        public List<KnowledgeDto> KnowledgeDtos { get; set; }

        /// <summary>
        /// 关键词
        /// </summary>
        public List<KnowledgeWordDto> KeywordsDto { get; set; }

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

        public List<KnowledgeTypeDto> KnowledgeTypes { get; set; }
        public List<OrgDto> KnowledgeOrganizes { get; set; }

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

    public class KnowledgeBaseDto
    {
        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; }
    }

    public class KnowledgeTitleDto
    {

        /// <summary>
        /// ID
        /// </summary>
        public string? Id { get; set; }

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

    }

    public class KnowledgeSearchNumDto
    {

        /// <summary>
        /// ID
        /// </summary>
        public string? Id { get; set; }

    }

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

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

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

        /// <summary>
        /// ID
        /// </summary>
        public string? Id { get; set; }
    }


    public class AddStartFlowDto : StartWorkflowDto<AddKnowledgeDto>
    {

    }

    public class UpdateStartFlowDto : StartWorkflowDto<UpdateKnowledgeDto>
    {

    }

    //public class DeleteStartFlowDto : StartWorkflowDto<KnowledgeDto>
    //{

    //}

    public class DeleteStartFlowDto : StartWorkflowDto<DeleteKnowledgeDto>
    {

    }

    public class OffShelfStartFlowDto : StartWorkflowDto<OffShelfKnowledgeDto>
    {

    }

    public class KnowledgeCollectGroupOutDto
    {
        /// <summary>
        /// Id
        /// </summary>
        public string Id { get; set; }

        /// <summary>
        /// 名字
        /// </summary>
        public string Name { get; set; }
    }

    public class KnowledgeCollectGroupInDto
    {
        /// <summary>
        /// 名字
        /// </summary>
        [Required]
        public string Name { get; set; }
    }

    public record KnowledgeCollectGroupListInDto : PagedKeywordRequest
    { }

    public class KnowledgeInfoExportInDto
    {
        /// <summary>
        /// 导入的知识Id集合
        /// </summary>
        public string[] Ids { get; set; }

        /// <summary>
        /// 导出格式
        /// </summary>
        public EFileType FileType { get; set; }
    }

    public record PageViewInDto : PagedRequest
    {
        /// <summary>
        /// 标题
        /// </summary>
        public string? Title { get; set; }

        /// <summary>
        /// 浏览人
        /// </summary>
        public string? CreatorName { get; set; }

        /// <summary>
        /// 知识分类Id
        /// </summary>
        public string? KnowledgeTypeId { get; set; }

        /// <summary>
        /// 开始时间
        /// </summary>
        public DateTime? StartTime { get; set; }

        /// <summary>
        /// 结束时间
        /// </summary>
        public DateTime? EndTime { get; set; }
    }

    public class PageViewOutDto
    {
        /// <summary>
        /// 标题
        /// </summary>
        public string KnowledgeTitle { get; set; }

        /// <summary>
        /// 浏览人
        /// </summary>
        public string CreatorName { get; set; }

        /// <summary>
        /// 浏览时间
        /// </summary>
        public DateTime CreationTime { get; set; }

        /// <summary>
        /// 浏览完成时间
        /// </summary>
        public DateTime? PvEndTime { get; set; }

        /// <summary>
        /// 浏览时长
        /// </summary>
        public int? BrowseTime { get; set; } = 0;
    }

    public class KnowledgeWordOutDto
    {
        public KnowledgeWordOutDto()
        {

        }
        public KnowledgeWordOutDto(string keyId, string tag)
        {
            Id = keyId;
            Tag = tag;
        }

        /// <summary>
        /// Id
        /// </summary>
        public string Id { get; set; }

        /// <summary>
        /// 标签
        /// </summary>
        public string Tag { get; set; }
    }

    public record KnowledgeHotWordInDto : PagedRequest
    {
        /// <summary>
        /// 热词
        /// </summary>
        public string? KeyWord { get; set; }

        /// <summary>
        /// 是否启用
        /// </summary>
        public bool? IsEnable { get; set; }

        /// <summary>
        /// 排序(需要被排序的字段名)
        /// </summary>
        public string? SortField { get; set; }

        /// <summary>
        /// 排序方向 (0: 升序Asc; 1: 降序Desc)
        /// </summary>
        public int OrderByType { get; set; } = 1;

        /// <summary>
        /// 热词类型
        /// </summary>
        public EKnowledgeHotWordType? Type { get; set; }
    }

    public class UpdateKnowledgeHotWordInDto : AddKnowledgeHotWordInDto
    {
        /// <summary>
        /// Id
        /// </summary>
        [Required]
        public string Id { get; set; }

        /// <summary>
        /// 点击次数
        /// </summary>
        public int? SearchCount { get; set; }

        /// <summary>
        /// 是否启用
        /// </summary>
        public bool? IsEnable { get; set; }
    }

    public class AddKnowledgeHotWordInDto
    {
        /// <summary>
        /// 热词
        /// </summary>
        public string? KeyWord { get; set; }

        /// <summary>
        /// 排序
        /// </summary>
        public int? Sort { get; set; }

        /// <summary>
        /// 热词类型
        /// </summary>
        public EKnowledgeHotWordType? Type { get; set; }
    }

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

        /// <summary>
        /// 热词类型
        /// </summary>
        public string TypeTxt => Type?.GetDescription();
    }

    public class KnowledgeBatchAuditInDto
    {
        /// <summary>
        /// 知识Id集合
        /// </summary>
        public string[] KnowledgeIds { get; set; }

        /// <summary>
        /// 是否通过
        /// </summary>
        public bool IsPass { get; set; }

        /// <summary>
        /// 办理意见
        /// </summary>
        public string Opinion { get; set; } = string.Empty;

        /// <summary>
        /// 是否短信通知
        /// </summary>
        public bool IsSms { get; set; }
    }
}
