using Hotline.Share.Enums.Order;
using XF.Utility.EnumExtensions;

namespace Hotline.Share.Requests;

public record PagedKeywordRequest : PagedRequest
{
    /// <summary>
    /// 开始时间
    /// </summary>
    public DateTime? StartTime { get; set; }

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

    public string? Keyword { get; set; }

    /// <summary>
    /// 排序字段 
    /// </summary>
    public string? SortField { get; set; }

    /// <summary>
    /// 排序规则  0 升序  1 降序
    /// </summary>
    public int? SortRule { get; set; }
}
public record PagedKeywordSonRequest : PagedRequest
{
    /// <summary>
    /// 开始时间
    /// </summary>
    public DateTime? StartTime { get; set; }

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

    public string? OrgName { get; set; }
    public string? OrgCode { get; set; }
    /// <summary>
    /// 1:办件结果 2:办件态度
    /// </summary>
    public int? TypeId { get; set; }

    public string? LineNum { get; set; }

    /// <summary>
    /// 来电/信人身份0：全部 ，1：市民，2：企业
    /// </summary>
    public int? TypeCode { get; set; }
}
public record VisitAndHotspotPagedKeywordRequest : PagedKeywordRequest
{
	/// <summary>
	/// 热点名称
	/// </summary>
	public string? HotspotName { get; set; }

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

	/// <summary>
	/// 1:办件结果 2:办件态度
	/// </summary>
	public int TypeId { get; set; }

	/// <summary>
	/// 标题名称
	/// </summary>

	public string? TitleCode { get; set; }
}
public record ReportPagedRequest : PagedKeywordRequest
{
    /// <summary>
    /// 来电/信人身份0：全部 ，1：市民，2：企业
    /// </summary>
    public int? TypeId { get; set; }
}

public record OrgDataListDetailRequest : PagedRequest
{
    /// <summary>
    /// 开始时间
    /// </summary>
    public DateTime StartTime { get; set; }
    /// <summary>
    /// 结束时间
    /// </summary>
    public DateTime EndTime { get; set; }
    /// <summary>
    /// 部门Code
    /// </summary>
    public string OrgCode { get; set; }

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

    /// <summary>
    /// 查询状态 1：业务已办超期  2：会签已办超期  3：业务待办超期  4：会签待办超期  5：小计
    /// </summary>
    public int QueryType { get; set; }

    /// <summary>
    /// 超期类型 1：系统中超期  2：申请延期超期
    /// </summary>
    public int ExpiredType { get; set; }

    /// <summary>
    /// 来电/信人身份0：全部 ，1：市民，2：企业
    /// </summary>
    public int? TypeId { get; set; }
}
/// <summary>
/// 部门超期全部数据
/// </summary>
public record OrgDataListAllDetailRequest : PagedRequest
{
	/// <summary>
	/// 开始时间
	/// </summary>
	public DateTime StartTime { get; set; }
	/// <summary>
	/// 结束时间
	/// </summary>
	public DateTime EndTime { get; set; }
	/// <summary>
	/// 部门Code
	/// </summary>
	public string OrgName { get; set; }

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

	/// <summary>
	/// 超期类型 1：系统中超期  2：申请延期超期
	/// </summary>
	public int ExpiredType { get; set; }

	/// <summary>
	/// 工单状态（√）
	/// </summary>
	public List<EOrderStatus> Statuses { get; set; } = new();
}

public record PublishedPagedRequest : PagedKeywordRequest
{
    /// <summary>
    /// 是否解决
    /// </summary>
    public bool? Resolve { get; set; }

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

public record HotspotSubtotalReportPagedRequest : ReportPagedRequest
{

    public string Id { get; set; }
}

public record HotPortJoinOrgStatisticsRequest
{
    public DateTime StartTime { get; set; }

    public DateTime EndTime { get; set; }
}


public record HotspotReportPagedRequest : ReportPagedRequest
{

    public string Id { get; set; }

    /// <summary>
    /// 查询类型  年 3 月 2 日 1 自定义 0
    /// </summary>
    public int Type { get; set; }

    public DateTime? ChainStartTime { get; set; }

    public DateTime? ChainEndTime { get; set; }
}


public record QuerySeatRestRequest : ReportPagedRequest
{
    public string? UserName { get; set; }

    public string? StaffNo { get; set; }

}

public record QuerySeatSwitchRequest : ReportPagedRequest
{
    public string? UserName { get; set; }

    public string? CDPN { get; set; }

}

public record QueryVisitNoSatiisfiedRequest : ReportPagedRequest
{
    public string? OrgName { get; set; }

}

public record BiQueryVisitNoSatisfiedDetailDto : ReportPagedRequest
{
    /// <summary>
    /// 部门Code
    /// </summary>
    public string OrgCode { get; set; }
    /// <summary>
    /// 不满意原因Key
    /// </summary>
    public string DissatisfiedKey { get; set; }
}

public record QueryOrderDelayDataListRequest : ReportPagedRequest
{
    public string? OrgName { get; set; }
}

public record QueryOrderDelayDataDetailRequest : ReportPagedRequest
{
    public string? OrgCode { get; set; }

    /// <summary>
    /// 查询类型  1已同意次数 2 未同意次数 3  审批中次数 4 小计
    /// </summary>
    public int? Type { get; set; }

}

public record QueryOrderReTransactRequest : ReportPagedRequest
{
    public string? OrgName { get; set; }

}

public record QuerySecondaryHandlingRequest : ReportPagedRequest
{
    public string? OrgName { get; set; }

    public string? OrgId { get; set; }

    /// <summary>
    ///  1  办件结果
    /// </summary>
    public int VisitTypeId { get; set; }

    public string? CDPN { get; set; }

    public string Header { get; set; }

}

public record QueryOrderReTransactDetailRequest : ReportPagedRequest
{
    public string? OrgName { get; set; }

    public string? ErrorName { get; set; }

    public string? No { get; set; }

}

public record QuerySendOrderRequest
{
    public string? UserName { get; set; }


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

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

}

public record QuerySendOrderDetailRequest : ReportPagedRequest
{
    public string UserId { get; set; }

    public string TitleCode { get; set; }
}

public record QueryUnsignedOrdersRequest : ReportPagedRequest
{
    /// <summary>
    ///  0 全部  1 本级  2 下级
    /// </summary>
    public int Level { get; set; }

    /// <summary>
    ///  0 未签收  1 签收
    /// </summary>
    public int Signed { get; set; }
}

public record QueryOrderSourceRequest : ReportPagedRequest
{
    /// <summary>
    /// 来电/信人身份0：全部 ，1：市民，2：企业
    /// </summary>
    public int? TypeId { get; set; }

    /// <summary>
    /// 导出列名
    /// </summary>
    public List<string> AddColumnName { get; set; }
}

public record QueryOrderSourceDetailRequest : QueryOrderSourceRequest
{
    /// <summary>
    /// 来电/信人身份0：全部 ，1：市民，2：企业
    /// </summary>
    public int? TypeId { get; set; }

    /// <summary>
    /// 点击时间
    /// </summary>
    public DateTime? Time { get; set; }

    /// <summary>
    /// 来源渠道（电话、网站、APP等）
    /// </summary>
    public string? SourceChannel { get; set; }
}

/// <summary>
/// 分时统计
/// </summary>
public record TimeSharingPagedKeywordRequest : PagedKeywordRequest
{
    /// <summary>
    /// 来电/信人身份0：全部 ，1：市民，2：企业
    /// </summary>
    public int? TypeId {  get; set; }

    /// <summary>
    /// 导出列名
    /// </summary>
    public List<string> AddColumnName { get; set; }
}


public record OrgVisitDetailListReq: PagedKeywordRequest
{
    /// <summary>
    /// 部门分类
    /// </summary>
    public EOrgVisitStatisticsType? OrgVisitStatisticsType { get; set; }

    /// <summary>
    /// 办件结果
    /// </summary>
    public string? OrgProcessingResults { get; set; }

    /// <summary>
    /// 回访人
    /// </summary>
    public string? VisitUser { get; set; }

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

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

    /// <summary>
    /// 回访部门
    /// </summary>
    public string OrgId { get; set; }

    /// <summary>
    /// 热点分类
    /// </summary>
    public string Hotspot { get; set; }

    /// <summary>
    /// 来源渠道（√）
    /// </summary>
    public string Channel { get; set; }

    /// <summary>
    /// 受理时间(工单创建时间)（√）
    /// </summary>
    public DateTime? CreationTimeStart { get; set; }
    public DateTime? CreationTimeEnd { get; set; }

    /// <summary>
    /// 办结时间（√）
    /// </summary>
    public DateTime? ActualHandleTimeStart { get; set; }
    public DateTime? ActualHandleTimeEnd { get; set; }
}


public record HotspotAndAreaStatisticsReq
{
    public int HotspotLevel { get; set; }

    public DateTime StartTime { get; set; }

    public DateTime EndTime { get; set; }

    /// <summary>
    /// 导出列名
    /// </summary>
    public List<string> AddColumnName { get; set; } = new();

}

public record AcceptTypeStatisticsByDateDetailReq:PagedRequest
{
    /// <summary>
    /// 日期
    /// </summary>
    public DateTime Date { get; set; }
    /// <summary>
    /// 工单编号
    /// </summary>
    public string No { get; set; }
    /// <summary>
    /// 工单标题
    /// </summary>
    public string Title { get; set; }
    /// <summary>
    /// 接办部门名称
    /// </summary>
    public string? CurrentHandleOrgName { get; set; }

    /// <summary>
    /// 受理类型Code
    /// </summary>
    public string AcceptTypeCode { get; set; }
}

public class AcceptTypeStatisticsByDateReq
{
    public DateTime StartTime { get; set; }

    public DateTime EndTime { get; set; }

    /// <summary>
    /// 0：全部 ，1：市民，2：企业
    /// </summary>
    public int? TypeId { get; set; }

    public string Gateway { get; set; }

    /// <summary>
    /// 导出列名
    /// </summary>
    public List<string> AddColumnName { get; set; } = new();
}

public class AcceptTypeStatisticsReq
{
    public DateTime StartTime { get; set; }

    public DateTime EndTime { get; set; }

    /// <summary>
    /// 0：全部 ，1：市民，2：企业
    /// </summary>
    public int? TypeId { get; set; }

    public string Gateway { get; set; }

   

}

public record HotspotAndAreaStatisticsDetailReq:PagedRequest
{
    public string? AreaCode { get; set; }

    public string HotspotId { get; set; }

    public DateTime StartTime { get; set; }

    public DateTime EndTime { get; set; }
}



public class HotspotAndAreaStatisticsDetailDto
{
    public EExpiredStatus? CalculateExpiredState()
    {
        DateTime? dateTime = DateTime.Now;
        if (Status >= EOrderStatus.Filed)
        {
            dateTime = ActualHandleTime;
        }
        if (ExpiredTime.HasValue)
        {
            if (NearlyExpiredTimeOne.HasValue && dateTime < NearlyExpiredTimeOne)
            {
                return EExpiredStatus.Normal;
            }
            else if (!NearlyExpiredTimeOne.HasValue && dateTime < NearlyExpiredTime)
            {
                return EExpiredStatus.Normal;
            }
            else if (NearlyExpiredTimeOne.HasValue && dateTime > NearlyExpiredTimeOne && dateTime < NearlyExpiredTime)
            {
                return EExpiredStatus.GoingToExpiredOne;
            }
            else if (dateTime > NearlyExpiredTime && dateTime < ExpiredTime)
            {
                return EExpiredStatus.GoingToExpired;
            }
            else
            {
                return EExpiredStatus.Expired;
            }
        }
        return null;
    }

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

    public string StatusText => Status.GetDescription();

    /// <summary>
    /// 来源渠道（电话、网站、APP等）
    /// </summary>
    public string? SourceChannel { get; set; }

    /// <summary>
    /// 过期状态
    /// </summary>
    public EExpiredStatus? ExpiredStatus => CalculateExpiredState();

    /// <summary>
    /// 过期状态
    /// </summary>
    public string ExpiredStatusText => ExpiredStatus?.GetDescription() ?? string.Empty;

    /// <summary>
    /// 当前节点
    /// </summary>
    public string? ActualHandleStepName { get; set; }

    /// <summary>
    /// 重办次数
    /// </summary>
    public int? ReTransactNum { get; set; }

    /// <summary>
    /// 紧急程度
    /// </summary>
    public bool IsUrgent { get; set; }

    public string IsUrgentText => IsUrgent ? "紧急" : "";

    /// <summary>
    /// 甄别状态
    /// </summary>
    public EScreenStatus? OrderScreenStatus { get; set; }

    public string OrderScreenStatusText => OrderScreenStatus?.GetDescription();

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

    /// <summary>
    /// 受理时间
    /// </summary>
    public DateTime CreationTime { get; set; }

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

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

    /// <summary>
    /// 即将超期时间
    /// </summary>
    public DateTime? NearlyExpiredTime { get; set; }

    /// <summary>
    /// 即将超期时间第一级
    /// </summary>
    public DateTime? NearlyExpiredTimeOne { get; set; }

    /// <summary>
    /// 接办部门名称
    /// </summary>
    public string? ActualHandleOrgName { get; set; }

    /// <summary>
    /// 接办时间
    /// </summary>
    public DateTime? ActualHandleTime { get; set; }

    /// <summary>
    /// 办结时间
    /// </summary>
    public DateTime? FiledTime { get; set; }

    /// <summary>
    /// 受理类型
    /// </summary>
    public string? AcceptType { get; set; }

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

    /// <summary>
    /// 受理人名称
    /// </summary>
    public string? AcceptorName { get; set; }
}


public class AcceptTypeStatisticsDto
{
    /// <summary>
    /// 受理类型
    /// </summary>
    public string AcceptType { get; set; }
    /// <summary>
    /// 分类量
    /// </summary>
    public int SumCount { get; set; }

    /// <summary>
    /// 办结量
    /// </summary>
    public int CompletionCount { get; set; }

    /// <summary>
    /// 办结率
    /// </summary>
    public string CompletionRate => SumCount > 0 ? Math.Round((double)CompletionCount / (double)SumCount * 100, digits: 3)+"%" : 0.000+"%";

    /// <summary>
    /// 回访量
    /// </summary>
    public int VisitCount { get; set; }

    /// <summary>
    /// 回访率
    /// </summary>
    public string VisitRate => SumCount > 0 ? Math.Round((double)VisitCount / (double)SumCount *100, digits: 3)+"%" : 0.000+"%";

    /// <summary>
    /// 占比
    /// </summary>
    public string SumCountRate { get; set; }
}

public record HotspotAndAcceptTypeStatisticsReq
{
	public int HotspotLevel { get; set; }

	public DateTime StartTime { get; set; }

	public DateTime EndTime { get; set; }

	/// <summary>
	/// 导出列名
	/// </summary>
	public List<string> AddColumnName { get; set; } = new();

}

public record HotspotAndAcceptTypeStatisticsDetailReq : PagedRequest
{
	public string? AcceptTypeCode { get; set; }

	public string HotspotId { get; set; }

	public DateTime StartTime { get; set; }

	public DateTime EndTime { get; set; }
}

public record OrderScreenApplyPagedRequest : PagedKeywordRequest
{
	/// <summary>
	/// 提起人
	/// </summary>
	public string ApplyUserName { get; set; }

	/// <summary>
	/// 部门名称
	/// </summary>
	public string ApplyOrgName { get; set; }
}

public record OrderScreenAuditPagedRequest : PagedKeywordRequest
{
	/// <summary>
	/// 审批人
	/// </summary>
	public string AuditUserName { get; set; }

	/// <summary>
	///  1 中心班长   2 中心领导
	/// </summary>
	public int? AuditType { get; set; }

}
