using Hotline.Share.Dtos.Knowledge;
using Hotline.Share.Dtos.Order;
using Hotline.Share.Dtos.Users;
using Hotline.Share.Enums.Article;
using Hotline.Share.Enums.Caselibrary;
using XF.Utility.EnumExtensions;

namespace Hotline.Share.Dtos.Caselibrary
{
    public record CaseDataDto
    {
        /// <summary>
        /// 案例ID
        /// </summary>
        public string Id { get; set; }

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

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

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

        /// <summary>
        /// 是否热门
        /// </summary>
        public bool IsPopular { get; set; }

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

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

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

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

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

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

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

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

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

        /// <summary>
        /// 审核人ID
        /// </summary>
        public string? ExaminManId { get; set; }

        /// <summary>
        /// 审核人
        /// </summary>
        public UserDto? ExaminMan { get; set; }

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

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

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

        /// <summary>
        /// 案例状态申请
        /// </summary>
        public ECaseApplyStatus? ApplyStatus { get; set; }

        /// <summary>
        /// 案例分类
        /// </summary>
        public List<CaseRelationTypeDto> CaseTypes { get; set; }

        /// <summary>
        /// 案例分类名称
        /// </summary>
        public string CaseTypeText => GetCaseTypeText(CaseTypes);

        /// <summary>
        /// 获取案例分类名称
        /// </summary>
        /// <returns></returns>
        public string GetCaseTypeText(List<CaseRelationTypeDto> items)
        {

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

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

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

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

        //public string OrderTitle => Order != null ? Order.Title : string.Empty;

        public string OrderTitle { get; set; }

        /// <summary>
        /// 知识库ID
        /// </summary>
        public string KnowledgeId { get; set; }

        /// <summary>
        /// 知识库
        /// </summary>
        //public KnowledgeDto Knowledge { get; set; }
        public string KnowledgeTitle { get; set; }

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

    public record CaseRelationTypeDto
    {
        /// <summary>
        /// 案例库类型ID
        /// </summary>
        public string Id { get; set; }

        /// <summary>
        /// 案例库类型名称
        /// </summary>
        public string Name { get; set; }


        /// <summary>
        /// 案例库类型名称
        /// </summary>
        public string SpliceName { get; set; }
    }
}


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

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

    /// <summary>
    /// 案例描述
    /// </summary>
    public string Describe { get; set; }

    /// <summary>
    /// 案例结果
    /// </summary>
    public string Result { get; set; }

    /// <summary>
    /// 推荐理由
    /// </summary>
    public string Reason { get; set; }

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

public class CaseInfoExportDto
{
    /// <summary>
    /// 导出的案例Id集合
    /// </summary>
    public string[] Ids { get; set; }

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


public class CaseInfoPopularDto
{
    /// <summary>
    /// 设置的案例Id集合
    /// </summary>
    public string[] Ids { get; set; }

    /// <summary>
    /// true热门  false非热门
    /// </summary>
    public bool Popular { get; set; }
}


public class CasePageViewDto
{
    public string Id { get; set; }
    public string Title { get; set; }
    public int PageView { get; set; }
}