using Hotline.Share.Dtos.Order;
using Hotline.Share.Enums.Early;
using Hotline.Share.Enums.Order;
using Hotline.Share.Requests;
using Lucene.Net.Util.Fst;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using XF.Utility.EnumExtensions;

namespace Hotline.Share.Dtos.Early
{
    #region 预警设置
    public class EarlySettingDto
    {
        public string Id { get; set; }
        /// <summary>
        /// 预警名称
        /// </summary>
        public string EarlyWarningName { get; set; }

        /// <summary>
        /// 预警级别名称
        /// </summary>
        public string EarlyWarningLevelName { get; set; }

        /// <summary>
        /// 预警级别值
        /// </summary>
        public string EarlyWarningLevelValue { get; set; }

        /// <summary>
        /// 预警类型名称
        /// </summary>
        public string EarlyWarningTypeName { get; set; }

        /// <summary>
        /// 预警类型值
        /// </summary>
        public string EarlyWarningTypeValue { get; set; }

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

        /// <summary>
        /// 预警原因
        /// </summary>
        public string EarlyWarningRemark { get; set; }

        /// <summary>
        /// 频率
        /// </summary>
        public EFrequency Frequency { get; set; }

        /// <summary>
        /// 频率
        /// </summary>
        public string FrequencyText => Frequency.GetDescription();

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

        /// <summary>
        /// 规则明细
        /// </summary>
        public List<EarlyWarningRuleDto> EarlyWarningRules { get; set; }
    }

    public record EarlyWarningRuleDto
    {
        /// <summary>
        /// 敏感词
        /// </summary>
        public string SensitiveWord { get; set; }

        /// <summary>
        /// 比较方式
        /// </summary>
        public ECompareType CompareType { get; set; }

        /// <summary>
        /// 比较方式
        /// </summary>
        public string CompareTypeText => CompareType.GetDescription();

        /// <summary>
        /// 次数
        /// </summary>
        public int Times { get; set; }

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

        /// <summary>
        /// 下一节点条件
        /// </summary>
        public ENextWhere? NextWhere { get; set; }
    }

    public record EarlySettingPageListRequest:PagedRequest
    {
        /// <summary>
        /// 预警名称
        /// </summary>
        public string? EarlyWarningName { get; set; }
        /// <summary>
        /// 预警级别
        /// </summary>
        public string? EarlyWarningLevelValue { get; set; }

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

    }
    public record UpdateEarlySettingRequest: AddEarlySettingRequest
    {
        public string Id { get; set; }
    }

    public record AddEarlySettingRequest
    {
        /// <summary>
        /// 预警名称
        /// </summary>
        public string EarlyWarningName { get; set; }

        /// <summary>
        /// 预警级别值
        /// </summary>
        public string EarlyWarningLevelValue { get; set; }

        /// <summary>
        /// 预警级别名称
        /// </summary>
        public string EarlyWarningLevelName { get; set; }

        /// <summary>
        /// 预警类型值
        /// </summary>
        public string EarlyWarningTypeValue { get; set; }

        /// <summary>
        /// 预警类型名称
        /// </summary>
        public string EarlyWarningTypeName { get; set; }

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

        /// <summary>
        /// 预警原因
        /// </summary>
        public string EarlyWarningRemark { get; set; }

        /// <summary>
        /// 预警规则
        /// </summary>

        public List<EarlyWarningRuleDto> EarlyWarningRules { get; set; }

        /// <summary>
        /// 频率
        /// </summary>
        public EFrequency Frequency { get; set; }
    }


    #endregion

    #region 预警管理

    public record EarlyOrderDto
    {
        public string Id { get; set; }
        /// <summary>
        /// 预警设置ID
        /// </summary>
        public string EarlyWarningSettingId { get; set; }

        /// <summary>
        /// 预警设置
        /// </summary>
        public EarlySettingDto EarlyWarningSetting { get; set; }

        /// <summary>
        /// 最后预警时间
        /// </summary>
        public DateTime LastEarlyTime { get; set; }

        public DateTime StartTime { get; set; }

        public DateTime EndTime { get; set; }

        /// <summary>
        /// 预警明细
        /// </summary>
        public List<EarlyWarningOrderDetailDto> EarlyWarningOrderDetails { get; set; }

        /// <summary>
        /// 行政区划编码
        /// </summary>
        public string? AreaCode { get; set; }

        /// <summary>
        /// 省
        /// </summary>
        public string? Province { get; set; }

        /// <summary>
        /// 市
        /// </summary>
        public string? City { get; set; }

        /// <summary>
        /// 区/县
        /// </summary>
        public string? County { get; set; }

        /// <summary>
        /// 乡镇(4级行政区划)
        /// </summary>
        public string? Town { get; set; }

        /// <summary>
        /// 村/社区
        /// </summary>
        public string? Village { get; set; }

        /// <summary>
        /// 完整地址
        /// </summary>
        public string? FullAddress { get; set; }
    }

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

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

        /// <summary>
        /// 工单内容快照
        /// </summary>
        public string OrderContent { get; set; }

        /// <summary>
        /// 工单标题快照
        /// </summary>
        public string OrderTitle { get; set; }

        /// <summary>
        /// 敏感标签
        /// </summary>
        public List<string>? Sensitive { get; set; }

        /// <summary>
        /// 工单推送状态
        /// </summary>
        public EOrderPushStatus OrderPushStatus { get; set; }

        /// <summary>
        /// 预警ID
        /// </summary>
        public string EarlyWarningOrderId { get; set; }
    }


    public record EarlyOrderPageListRequest: PagedRequest
    {
        /// <summary>
        /// 预警名称
        /// </summary>
        public string? EarlyWarningName { get; set; }

        /// <summary>
        /// 预警级别
        /// </summary>
        public string? EarlyWarningLevelValue { get; set; }

    }

    #endregion

    #region 报告管理

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

        /// <summary>
        /// 推送报告名称
        /// </summary>
        public string EarlyWarningPushName { get; set; }

        /// <summary>
        /// 推送部门
        /// </summary>
        public List<PushOrgDto> PushOrgs { get; set; }

        /// <summary>
        /// 报告状态
        /// </summary>
        public EEarlyPushStatus PushStatus { get; set; }

        /// <summary>
        /// 办理中数量（推送后）
        /// </summary>
        public int? ProcessingCount { get; set; }

        /// <summary>
        /// 办理完成数量（推送后）
        /// </summary>
        public int? FiledCount { get; set; }

        /// <summary>
        /// 推送时间
        /// </summary>
        public DateTime? PushTime { get; set; }

        /// <summary>
        /// 推送报告下载地址
        /// </summary>
        public string? PushReportUrl { get; set; }

        /// <summary>
        /// 报告明细
        /// </summary>
        public List<EarlyWarningPushDetailDto> EarlyWarningPushDetails { get; set; }

    }

    public record EarlyWarningPushDetailDto
    {
        public string? EarlyWarningPushId { get; set; }

        public string OrderId { get; set; }

        /// <summary>
        /// 是否生成word
        /// </summary>
        public bool IsSendWord { get; set; }

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

    public record PushOrgDto
    {
        public string OrgCode { get; set; }

        public string OrgName { get; set; }
    }

    public record EarlyPushPageListRequest:PagedRequest
    {
        /// <summary>
        /// 推送报告名称
        /// </summary>
        public string EarlyWarningPushName { get; set; }

        /// <summary>
        /// 推送状态
        /// </summary>
        public EEarlyPushStatus? EarlyPushStatus { get; set; }
    }

    public record CanChooseOrderRequest:PagedRequest
    {
        /// <summary>
        /// 已选工单列表
        /// </summary>
        public List<string> ChooseOrderId { get; set; }

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

        /// <summary>
        /// 工单编号
        /// </summary>
        public string? No { get; set; }

        /// <summary>
        /// 工单状态
        /// </summary>
        public EOrderStatus? OrderStatus { get; set; }

        /// <summary>
        /// 推送状态
        /// </summary>
        public EOrderPushStatus? OrderPushStatus { get; set; }

    }

    public record CanChooseOrderRsp
    {
        public string Id { get; set; }
        public OrderDto Order { get; set; }

        public EOrderPushStatus OrderPushStatus { get; set; }

        public string? OrderPushStatusText => OrderPushStatus.GetDescription();
    }

    public record AddEarlyPushRequest
    {
        public string EarlyWarningPushName { get; set; }

        public List<PushOrgDto> PushOrg { get; set; }

        /// <summary>
        /// 操作方式  1：暂存  2：推送 3：推送并生成报告
        /// </summary>
        public int OperateModel { get; set; }


        public List<EarlyWarningPushDetailDto> EarlyWarningPushDetails { get; set; }
    }

    public record ReportReceiveRequest:PagedRequest
    {
        /// <summary>
        /// 推送报告名称
        /// </summary>
        public string EarlyWarningPushName { get; set; }
    }

    public class EarlyReportDto
    {
        /// <summary>
        /// 报告名称
        /// </summary>
        public string ReportName { get; set; }

        /// <summary>
        /// 报告时间
        /// </summary>
        public DateTime ReportPushTime { get; set; }

        /// <summary>
        /// 热点汇报简介
        /// </summary>
        public List<ReportHotDetailDto> ReportHotDetails { get; set; }

        /// <summary>
        /// 区域汇报简介
        /// </summary>
        public List<ReportAreaDetailDto> ReportAreaDetails { get; set; }

        /// <summary>
        /// 工单明细表
        /// </summary>
        public List<ReportOrderDetailDto> ReportOrderDetails { get; set; }

        /// <summary>
        /// 往期明细工单
        /// </summary>
        public List<ReportFiledOrderDetailDto> ReportFiledOrderDetails { get; set; }
    }

    public class ReportAreaDetailDto
    {
        /// <summary>
        /// 区县名称
        /// </summary>
        public string AreaName { get; set; }

        /// <summary>
        /// 数量
        /// </summary>
        public int Count { get; set; }
    }

    public class ReportHotDetailDto
    {
        /// <summary>
        /// 热点名称
        /// </summary>
        public string HotName { get; set; }

        /// <summary>
        /// 数量
        /// </summary>
        public int Count { get; set; }

        /// <summary>
        /// 主要涉及
        /// </summary>
        public string Content { get; set; }
    }

    public class ReportOrderDetailDto
    {
        /// <summary>
        /// 一级热点
        /// </summary>
        public string OneHotSportName { get; set; }

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

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

        /// <summary>
        /// 办理情况
        /// </summary>
        public string ActualOpinion { get; set; }
    }

    public class ReportFiledOrderDetailDto
    {
        /// <summary>
        /// 期刊
        /// </summary>
        public string ReportName { get; set; }

        /// <summary>
        /// 一级热点
        /// </summary>
        public string OneHotSportName { get; set; }

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

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

        /// <summary>
        /// 办理情况
        /// </summary>
        public string ActualOpinion { get; set; }
    }


    public class ReportOrderListDto()
    {
        /// <summary>
        /// 工单ID
        /// </summary>
        public string Id { get; set; }

        /// <summary>
        /// 实际办理部门
        /// </summary>
        public string ActualHandleOrgName { get; set; }

        /// <summary>
        /// 是否生成Word
        /// </summary>
        public bool IsSendWord { get; set; }

        /// <summary>
        /// 区县
        /// </summary>
        public string County { get; set; }

        /// <summary>
        /// 一级热点
        /// </summary>
        public string OneHotspotName { get; set; }

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

        /// <summary>
        /// 工单状态
        /// </summary>
        public EOrderStatus Status { get; set; }

        /// <summary>
        /// 归档意见
        /// </summary>
        public string FileOpinion { get; set; }

        /// <summary>
        /// 诉求内容
        /// </summary>
        public string Content { get; set; }
    }
    #endregion
}
