using Hotline.Share.Dtos.File;
using Hotline.Share.Dtos.Knowledge;
using Hotline.Share.Enums.Planlibrary;
using Hotline.Share.Requests;

namespace Hotline.Share.Dtos.Planlibrary
{
    /// <summary>
    /// 预案库列表
    /// </summary>
    public record PlanListDto : PagedRequest
    {
        /// <summary>
        /// 标题
        /// </summary>
        public string Title { get; set; }

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

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


        /// <summary>
        /// 预案状态
        /// </summary>
        public EPlanStatus? Status { get; set; }

        /// <summary>
        /// 预案归属
        /// </summary>
        public string? Attribution { get; set; }

        /// <summary>
        /// 分类ID
        /// </summary>
        public string? PlanTypeID { get; set; }

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

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

        /// <summary>
        /// 是否删除
        /// </summary>
        public bool? IsDeleted { get; set; } = false;

        /// <summary>
        /// 阅读次数
        /// </summary>
        public int PageView { get; set; } = 0;

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

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

        /// <summary>
        /// 上架开始时间
        /// </summary>
        public DateTime? OnShelfTimeStart { get; set; }
        /// <summary>
        /// 上架结束时间
        /// </summary>
        public DateTime? OnShelfTimeEnd { get; set; }

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

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

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

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

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

        /// <summary>
        /// 审核部门ID
        /// </summary>
        public string? ExaminOrganizeId { get; set; }

        /// <summary>
        /// 当前部门ID
        /// </summary>
        public string CreateOrgId { get; set; }

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

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

        /// <summary>
        /// 失效时间
        /// </summary>
        public DateTime? ExpiredTime { get; set; }

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

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


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

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

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

        /// <summary>
        /// 预案归属
        /// </summary>
        public string Attribution { get; set; }

        ///// <summary>
        ///// 分类ID
        ///// </summary>
        //public string? PlanTypeID { get; set; }

        /// <summary>
        /// 分类
        /// </summary>
        public List<PlanRelationTypeDto> PlanTypes { get; set; }

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

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

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

        /// <summary>
        /// 失效时间
        /// </summary>
        public DateTime? ExpiredTime { get; set; }

        /// <summary>
        /// 预案状态
        /// </summary>
        public EPlanApplyStatus? ApplyStatus { get; set; }

        /// <summary>
        /// 预案状态
        /// </summary>
        public EPlanStatus? Status { get; set; }

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

    public record UpdatePlanListDto : AddPlanListDto
    {
        /// <summary>
        /// 预案库ID
        /// </summary>
        public string Id { get; set; }

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

        /// <summary>
        /// 审核部门ID
        /// </summary>
        public string? ExaminOrganizeId { get; set; }

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

        /// <summary>
        /// 修改时间
        /// </summary>
        public DateTime? UpdateTime { get; set; }

        /// <summary>
        /// 申请理由
        /// </summary>
        public string ApplyReason { get; set; }

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

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

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

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

        /// <summary>
        /// 申请理由
        /// </summary>
        public string ApplyReason { get; set; }
    }


    /// <summary>
    /// 预案库列表
    /// </summary>
    public record PlanInfoDto
    {
        /// <summary>
        /// 标识
        /// </summary>
        public string Id { get; set; }

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

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

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

        /// <summary>
        /// 预案归属
        /// </summary>
        public string? Attribution { get; set; }

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

        /// <summary>
        /// 阅读次数
        /// </summary>
        public int PageView { get; set; } = 0;

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

        /// <summary>
        /// 失效时间
        /// </summary>
        public DateTime? ExpiredTime { get; set; }

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

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

        /// <summary>
        /// 创建部门
        /// </summary>
        public string? CreatorOrgName { get; set; }


        /// <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 HotspotName { get; set; }

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

        public PlanCollectDto Collect { get; set; }

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

        /// <summary>
        /// 预案状态
        /// </summary>
        public EPlanStatus Status { get; set; }


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

        /// <summary>
        /// 附件
        /// </summary>
        public List<FileJson>? FileJson { get; set; }
    }

    public class PlanCollectDto
    {
        /// <summary>
        /// 预案库ID
        /// </summary>
        public string PlanId { get; set; }

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

        /// <summary>
        /// 是否收藏
        /// </summary>
        public bool? Collect { get; set; }
    }

    public class PlanApplyReasonDto
    {
        /// <summary>
        /// 预案库ID
        /// </summary>
        public string Id { get; set; }

        /// <summary>
        /// 申请理由
        /// </summary>
        public string? ApplyReason { get; set; }
    }


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

        /// <summary>
        /// 审核状态 0不同意 1同意
        /// </summary>
        public int State { get; set; }

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

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

        /// <summary>
        /// 浏览量：默认不增加，false不增加，true增加浏览量
        /// </summary>
        public bool IsAddPv { get; set; } = false;

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