using Hotline.Share.Enums.Article;
using Hotline.Share.Requests;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Hotline.Share.Dtos.Users;
using XF.Utility.EnumExtensions;
using Hotline.Share.Tools;
using Hotline.Share.Dtos.File;

namespace Hotline.Share.Dtos.Article
{
    public record BulletinDto
    {
        public string Id { get; set; }

        public DateTime CreationTime { get; set; }

        public string Title { get; set; }

        public string Content { get; set; }

        public string BulletinTypeId { get; set; }

        public string BulletinTypeName { get; set; }

        /// <summary>
        /// 阅读量
        /// </summary>
        public int ReadedNum { get; set; }

        /// <summary>
        /// 通知时间
        /// </summary>
        public DateTime? BulletinTime { get; set; }

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

        /// <summary>
        /// 公告状态
        /// </summary>
        public EBulletinState BulletinState { get; set; }

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

        /// <summary>
        /// 发布范围（多选）  位枚举  EPushRange
        /// </summary>
        public List<Kv> PushRanges { get; set; }

        /// <summary>
        /// 显示位置（多选） 位枚举  BulletinDisplayLocation
        /// </summary>
        public List<Kv> DisplayLocation { get; set; }

        /// <summary>
        /// 来源单位ID
        /// </summary>
        public string SourceOrgId { get; set; }

        /// <summary>
        /// 来源单位名称
        /// </summary>
        public string SourceOrgName { 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 DateTime? CommitTime { get; set; }

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

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

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

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

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


        public string BulletinStateText => BulletinState.GetDescription();

        public string PushRangesText => PushRanges != null && PushRanges.Any() ? string.Join("、", PushRanges.Select(x => x.Value)) : "-";

        public string DisplayLocationText => DisplayLocation != null && DisplayLocation.Any() ? string.Join("、", DisplayLocation.Select(x => x.Value)) : "-";

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

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

    public record CircularDto
    {
        public string Id { get; set; }

        public DateTime CreationTime { get; set; }

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

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

        /// <summary>
        /// 通知类型
        /// </summary>
        public string CircularTypeId { get; set; }

        /// <summary>
        /// 通知类型名称
        /// </summary>
        public string CircularTypeName { get; set; }

        /// <summary>
        /// 是否必读
        /// </summary>
        public bool IsMustRead { get; set; }

        /// <summary>
        /// 通知对象
        /// </summary>
        public ECircularType CircularType { get; set; }

        public string CircularTypeText => CircularType.GetDescription();

        /// <summary>
        /// 通知时间
        /// </summary>
        public DateTime? CircularTime { get; set; }

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

        /// <summary>
        /// 通知状态
        /// </summary>
        public ECircularState CircularState { get; set; }

        public string CircularStateText => CircularState.GetDescription();
        /// <summary>
        /// 来源单位ID
        /// </summary>
        public string SourceOrgId { get; set; }

        /// <summary>
        /// 来源单位名称
        /// </summary>
        public string SourceOrgName { get; set; }

        /// <summary>
        /// 需要阅读数量
        /// </summary>
        public int NeedReadNum { get; set; }

        /// <summary>
        /// 已读数量
        /// </summary>
        public int ReadedNum { get; set; }

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

        /// <summary>
        /// 阅读明细
        /// </summary>
        public List<CircularReadGroupDto> CircularReadGroups { get; set; }

        /// <summary>
        /// 提交时间
        /// </summary>
        public DateTime? CommitTime { get; set; }

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

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

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

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

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

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

    public record CircularReadGroupDto
    {
        public string? CircularId { get; set; }

        public string? UserId { get; set; }
        public string? UserName { get; set; }

        public string? OrgId { get; set; }

        public string? OrgName { get; set; }

        public bool? IsRead { get; set; }

        public DateTime? ReadTime { get; set; }

        public bool? IsTimeOut { get; set; }
    }

    public record AddCircularDto
    {
        /// <summary>
        /// 标题
        /// </summary>
        public string Title { get; set; }
        /// <summary>
        /// 内容
        /// </summary>
        public string Content { get; set; }
        /// <summary>
        /// 通知类型
        /// </summary>
        public string CircularTypeId { get; set; }
        /// <summary>
        /// 通知类型名称
        /// </summary>
        public string CircularTypeName { get; set; }
        /// <summary>
        /// 通知对象
        /// </summary>
        public ECircularType CircularType { get; set; }
        /// <summary>
        /// 是否必读
        /// </summary>
        public bool IsMustRead { get; set; }

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

        /// <summary>
        /// 来源单位ID
        /// </summary>
        public string SourceOrgId { get; set; }

        /// <summary>
        /// 来源单位名称
        /// </summary>
        public string SourceOrgName { get; set; }

        public List<CircularReadGroupDto> CircularReadGroups { get; set; }

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

    public record UpdateCircularDto : AddCircularDto
    {
        public string Id { get; set; }
    }

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

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

        /// <summary>
        /// 公告类型
        /// </summary>
        public string BulletinTypeId { get; set; }

        /// <summary>
        /// 公告类型名称
        /// </summary>
        public string BulletinTypeName { get; set; }

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

        /// <summary>
        /// 发布范围  EPushRange
        /// </summary>
        public List<Kv> PushRanges { get; set; }

        /// <summary>
        /// 来源单位ID
        /// </summary>
        public string SourceOrgId { get; set; }

        /// <summary>
        /// 来源单位名称
        /// </summary>
        public string SourceOrgName { get; set; }

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

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

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

        /// <summary>
        /// 公告类型
        /// </summary>
        public string BulletinTypeId { get; set; }

        /// <summary>
        /// 公告类型名称
        /// </summary>
        public string BulletinTypeName { get; set; }

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

        /// <summary>
        /// 发布范围  EPushRange
        /// </summary>
        public List<Kv> PushRanges { get; set; }

        /// <summary>
        /// 显示位置（多选） 位枚举  BulletinDisplayLocation
        /// </summary>
        public List<Kv> DisplayLocation { get; set; }

        /// <summary>
        /// 来源单位ID
        /// </summary>
        public string SourceOrgId { get; set; }

        /// <summary>
        /// 来源单位名称
        /// </summary>
        public string SourceOrgName { get; set; }

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

    public record BulletinArriveDto
    {
        public string Id { get; set; }

        /// <summary>
        /// 上架true  下架false
        /// </summary>
        public bool IsArrive { get; set; }

    }
    public record UpdateBulletinDto : AddBulletinDto
    {
        public string Id { get; set; }
    }


    public record QueryCircularListRequestDto : PagedRequest
    {
        /// <summary>
        /// 标题
        /// </summary>
        public string Title { get; set; }
        /// <summary>
        /// 通知类型
        /// </summary>
        public string CircularTypeId { get; set; }

        /// <summary>
        /// 开始时间
        /// </summary>
        public DateTime? CircularTimeStart { get; set; }
        /// <summary>
        /// 结束时间
        /// </summary>
        public DateTime? CircularTimeEnd { get; set; }

        /// <summary>
        /// 状态
        /// </summary>
        public ECircularState? CircularState { get; set; }

        /// <summary>
        /// 是否阅读
        /// </summary>
        public bool? IsRead { get; set; }

    }


    public record ExamineCircularDto
    {
        public string Id { get; set; }

        public bool IsPass { get; set; }

        public string Reason { get; set; }
    }

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

        /// <summary>
        /// 通知类型
        /// </summary>
        public string BulletinTypeId { get; set; }

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

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

        /// <summary>
        /// 公告状态
        /// </summary>
        public EBulletinState? BulletinState { get; set; }

        /// <summary>
        /// 是否查询包含失效
        /// </summary>
        public bool? IsLoseEfficacy { get; set; }
    }

    public record ExamineBulletinDto
    {
        public string Id { get; set; }

        public bool IsPass { get; set; }

        public string Reason { get; set; }
    }

    public record CircularRecordDto
    {
        public int PersonCount { get; set; }

        public int OrgCount { get; set; }
    }

    /// <summary>
    /// 微信小程序获取宣传学习列表入参
    /// </summary>
    public class BulletinInDto : QueryFixedDto
    {
        /// <summary>
        /// 行业Id
        /// <inheritdoc cref="Hotline.Snapshot.Industry" />表的Id
        /// </summary>
        public string IndustryId { get; set; }
    }

    public class BulletinListOutDto
    { 
        /// <summary>
        /// 公告ID
        /// </summary>
        public string Id { get; set; }

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

        private string content;
        /// <summary>
        /// 内容
        /// </summary>
        public string Content { get { return content.RemoveHtmlTags(); } set { content = value; } }

        public DateTime CreationTime { get; set; }
    }

    /// <summary>
    /// 微信小程序获取宣传学习列表出参
    /// </summary>
    public class BulletinOutDto
    {
        /// <summary>
        /// 公告ID
        /// </summary>
        public string Id { get; set; }

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

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

        /// <summary>
        /// 视频地址
        /// </summary>
        public string? VideoPath { get; set; }

        public DateTime CreationTime { get; set; }
    }
}
