using Hotline.Share.Dtos.Hotspots;
using Hotline.Share.Dtos.Users;
using Hotline.Share.Enums.Article;
using Hotline.Share.Enums.Planlibrary;
using XF.Utility.EnumExtensions;

namespace Hotline.Share.Dtos.Planlibrary
{
    public record PlanDataDto
    {
        /// <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 IsPublic { 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 string? Attribution { get; set; }

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

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

        /// <summary>
        /// 文档状态申请
        /// </summary>
        public EPlanApplyStatus ApplyStatus { get; set; }

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

        /// <summary>
        /// 预案分类
        /// </summary>
        public List<PlanRelationTypeDto2> PlanTypes { get; set; }

        /// <summary>
        /// 预案分类名称
        /// </summary>
        public string PlanTypeText => GetPlanTypeText(PlanTypes);

        /// <summary>
        /// 获取预案分类名称
        /// </summary>
        /// <returns></returns>
        public string GetPlanTypeText(List<PlanRelationTypeDto2> items)
        {

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

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

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

        public HotspotDto? HotspotType { get; set; }

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

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

    }

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

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


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

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

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


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


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

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

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


public class PlanInfoExportDto
{
    /// <summary>
    /// 导入的预案Id集合
    /// </summary>
    public string[] Ids { get; set; }

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


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