using Hotline.Share.Dtos.File;
using Hotline.Share.Dtos.Settings;
using Hotline.Share.Enums.Order;
using Hotline.Share.Requests;
using XF.Utility.EnumExtensions;

namespace Hotline.Share.Dtos.Order;

public class PublishedDto
{
    public string Id { get; set; }

    public OrderDto Order { get; set; }

    /// <summary>
    /// 发布范围
    /// </summary>
    public bool? PublishState { get; set; }

    /// <summary>
    /// 
    /// </summary>
    public string PublishStateText => PublishState == true ? "公开" : "不公开";

    /// <summary>
    /// 整理内容
    /// </summary>
    public string? ArrangeContent { get; set; }

    /// <summary>
    /// 发布时间
    /// </summary>
    public DateTime? PublishTime { get; set; }

    public string? PublishMan { get; set; }

    public bool? Resolve { get; set; }

    /// <summary>
    /// 最近更新时间
    /// </summary>
    public DateTime? LastModificationTime { get; set; }
}

public class PublishedOrderStatisticsDto
{
    /// <summary>
    /// 待发布量
    /// </summary>
    public int WaitCount { get; set; }

    /// <summary>
    /// 公开发布量
    /// </summary>
    public int PublicCount { get; set; }

    /// <summary>
    /// 不公开发布量
    /// </summary>
    public int PrivateCount { get; set; }

    //private int totalCount;
    /// <summary>
    /// 总量
    /// </summary>
    public int TotalCount => WaitCount + PublicCount + PrivateCount;
    //{
    //    get
    //    {
    //        if (totalCount == 0)
    //            return WaitCount + PublicCount + PrivateCount;
    //        return totalCount;
    //    }
    //    set
    //    {
    //        totalCount = value;
    //    }
    //}

    /// <summary>
    /// 名字
    /// </summary>
    public string Name { get; set; }

    /// <summary>
    /// 发布人ID
    /// </summary>
    public string Id { get; set; }

    /// <summary>
    /// 发布时间
    /// </summary>
    public string PublishTime { get; set; }
}

public class QueryPublishedOrderDataDto
{
    /// <summary>
    /// 发布人名称
    /// </summary>
    public string Name { get; set; }

    /// <summary>
    /// 发布人ID
    /// </summary>
    public string Id { get; set; }

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

    /// <summary>
    /// 发布时间
    /// </summary>
    public string CreationTime { get; set; }
}

public class PublishDto : OrderDto
{
    /// <summary>
    /// 发布范围
    /// </summary>
    public bool? PublishState { get; set; }

    public string PublishStateText => PublishState == true ? "公开" : "不公开";

    /// <summary>
    /// 整理内容
    /// </summary>
    public string? ArrangeContent { get; set; }

    /// <summary>
    /// 发布时间
    /// </summary>
    public DateTime? PublishTime { get; set; }

    public string? PublishMan { get; set; }

    public bool? Resolve { get; set; }
}


public class PublishOrderPageBaseDto
{
    /// <summary>
    /// 来源 0：热线平台  1：省平台 2：110
    /// </summary>
    public string SourceChannel { get; set; }

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

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

    /// <summary>
    /// 办理结果
    /// </summary>
    public string ActualOpinion { get; set; }

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

    /// <summary>
    /// 需回访部门
    /// </summary>
    public List<Kv>? idNames { get; set; }

    public List<Kv>? NetizenEvaluateType { get; set; }

    /// <summary>
    /// 是否随手拍工单
    /// </summary>
    public bool IsSnapshot { get; set; }

    /// <summary>
    /// 随手拍工单标签
    /// </summary>
    public IReadOnlyCollection<SystemDicDataOutDto> SnapshotLabel { get; set; }

    /// <summary>
    /// 诉求人意愿是否公开（省政府网站、省政务服务网、天府通办App）
    /// </summary>
    public bool? IsPublic { get; set; }

    /// <summary>
    /// 省工单是否可以选择意愿是否公开
    /// </summary>
    public bool IsProvincePublic { get; set; } = false;
}

public class PublishPublishOrderDto
{
    public string Id { get; set; }

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

    public OrderDto Order { get; set; }

    /// <summary>
    /// 发布范围
    /// </summary>
    public bool PublishState { get; set; }

    /// <summary>
    /// 整理标题
    /// </summary>
    public string ArrangeTitle { get; set; }

    /// <summary>
    /// 整理内容
    /// </summary>
    public string ArrangeContent { get; set; }

    /// <summary>
    /// 整理结果
    /// </summary>
    public string ArrangeOpinion { get; set; }

    /// <summary>
    /// 需回访部门
    /// </summary>
    public List<Kv> IdNames { get; set; }

    /// <summary>
    /// 发布人
    /// </summary>
    public string CreatorName { get; set; }
    /// <summary>
    /// 发布时间
    /// </summary>
    public DateTime CreationTime { get; set; }

    /// <summary>
    /// 实际办理附件
    /// </summary>
    public List<FileJson>? FileJsons { get; set; }
    #region 省工单使用
    #region 中国政府网
    /// <summary>
    /// 省是否公开
    /// </summary>
    public bool? ProPublishState { get; set; }
    /// <summary>
    /// 反馈人电话
    /// </summary>
    public string? FeedBackPhone { get; set; }

    /// <summary>
    /// 不公开原因(省工单公用)
    /// </summary>
    public string? NoPubReason { get; set; }

    /// <summary>
    /// 是否联系
    /// </summary>
    public bool? IsContact { get; set; }

    /// <summary>
    /// 是否评价
    /// </summary>
    public bool? IsVisited { get; set; }

    /// <summary>
    /// 网民评价
    /// </summary>
    public Kv? NetizenEvaluate { get; set; }

    /// <summary>
    /// 评价内容
    /// </summary>
    public string? EvaluateContent { get; set; }

    /// <summary>
    /// 备注
    /// </summary>
    public string Remark { get; set; }

    /// <summary>
    /// 答复口径
    /// </summary>
    public string AnswerContent { get; set; }
    #endregion

    #region  省政府网、省政务服务网、天府通办App
    /// <summary>
    /// 是否开展保密审查
    /// </summary>
    public bool? IsOpenReview { get; set; }
    #endregion
    #endregion
}


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

    /// <summary>
    /// 发布范围
    /// </summary>
    public bool PublishState { get; set; }

    /// <summary>
    /// 整理标题
    /// </summary>
    public string ArrangeTitle { get; set; }

    /// <summary>
    /// 整理内容
    /// </summary>
    public string ArrangeContent { get; set; }

    /// <summary>
    /// 整理结果
    /// </summary>
    public string ArrangeOpinion { get; set; }

    /// <summary>
    /// 需回访部门
    /// </summary>
    public List<Kv> IdNames { get; set; }

    #region 省工单使用

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

    /// <summary>
    /// 反馈人电话
    /// </summary>
    public string? FeedBackPhone { get; set; }

    /// <summary>
    /// 不公开原因
    /// </summary>
    public string? NoPubReason { get; set; }

    /// <summary>
    /// 是否联系
    /// </summary>
    public bool? IsContact { get; set; }

    /// <summary>
    /// 是否评价
    /// </summary>
    public bool? IsVisited { get; set; }

    /// <summary>
    /// 网民评价
    /// </summary>
    public Kv? NetizenEvaluate { get; set; }

    /// <summary>
    /// 评价内容
    /// </summary>
    public string? EvaluateContent { get; set; }

    /// <summary>
    /// 备注
    /// </summary>
    public string? Remark { get; set; }

    /// <summary>
    /// 答复口径
    /// </summary>
    public string? AnswerContent { get; set; }

    #endregion

    /// <summary>
    /// 是否开展保密审查
    /// </summary>
    public bool? IsOpenReview { get; set; }

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

    /// <summary>
    /// 随手拍工单标签
    /// </summary>
    public IList<Kv>? SnapshotLabels { get; set; }
}


public class BatchPublishOrderDto
{
    public string[] Ids { get; set; }
}


public class PublishOrderModifyDto
{
    /// <summary>
    /// 发布ID
    /// </summary>
    public string Id { get; set; }


    /// <summary>
    /// 整理标题
    /// </summary>
    public string ArrangeTitle { get; set; }

    /// <summary>
    /// 整理内容
    /// </summary>
    public string ArrangeContent { get; set; }

    /// <summary>
    /// 整理结果
    /// </summary>
    public string ArrangeOpinion { get; set; }

    /// <summary>
    /// 发布范围
    /// </summary>
    public bool PublishState { get; set; }
}

public class SuperviseOrderDto
{

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

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

    /// <summary>
    /// 督办回复时限
    /// </summary>
    public DateTime ReplyLimitTime { get; set; }

    /// <summary>
    /// 被督办部门ID
    /// </summary>
    public string OrgId { get; set; }

    /// <summary>
    /// 被督办部门名称
    /// </summary>
    public string OrgName { get; set; }


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

    /// <summary>
    /// 督办状态
    /// </summary>
    public int State { get; set; }

    public string StateText => State == 0 ? "待办未读" : State == 1 ? "已回复" : State == 2 ? "签收已读" : "-";

    /// <summary>
    /// 督办签收时间
    /// </summary>
    public DateTime? SignTime { get; set; }

    /// <summary>
    /// 督办回复时间
    /// </summary>
    public DateTime? ReplyTime { get; set; }

    /// <summary>
    /// 督办申请内容
    /// </summary>
    public string? ApplyContent { get; set; }

    /// <summary>
    /// 督办回复内容
    /// </summary>
    public string? ReplyContent { get; set; }

    /// <summary>
    /// 回复人
    /// </summary>
    public string? ReplyId { get; set; }

    /// <summary>
    /// 附件
    /// </summary>
    public List<FileJson>? FileJson { get; set; } = new();

    public DateTime? LastModificationTime { get; set; }

    public string? CreatorId { get; set; }

    public string? CreatorOrgId { get; set; }

    public DateTime CreationTime { get; set; }

    /// <summary>
    /// 工单对象
    /// </summary>
    public OrderDto Order { get; set; }
    public string ReUser { get; set; }
    public string CrUser { get; set; }
    public string SignUser { get; set; }

    /// <summary>
    /// 督办省编号
    /// </summary>
    public string? SuperviseSerial { get; set; }

    /// <summary>
    /// 发起部门名称
    /// </summary>
    public string? LaunchOrgName { get; set; }
}


public class UrgeOrderDto
{

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

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

    /// <summary>
    /// 催办回复时限
    /// </summary>
    public DateTime ReplyLimitTime { get; set; }

    /// <summary>
    /// 被催办部门ID
    /// </summary>
    public string OrgId { get; set; }

    /// <summary>
    /// 被催办部门名称
    /// </summary>
    public string OrgName { get; set; }

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

    /// <summary>
    /// 催办状态
    /// </summary>
    public int State { get; set; }

    public string StateText => State == 0 ? "待办未读" : State == 1 ? "已回复" : State == 2 ? "签收已读" : "-";

    /// <summary>
    /// 催办签收时间
    /// </summary>
    public DateTime? SignTime { get; set; }

    /// <summary>
    /// 催办回复时间
    /// </summary>
    public DateTime? ReplyTime { get; set; }

    /// <summary>
    /// 催办申请内容
    /// </summary>
    public string? ApplyContent { get; set; }

    /// <summary>
    /// 催办回复内容
    /// </summary>
    public string? ReplyContent { get; set; }

    /// <summary>
    /// 回复人
    /// </summary>
    public string? ReplyId { get; set; }

    /// <summary>
    /// 附件
    /// </summary>
    public List<FileJson>? FileJson { get; set; } = new();

    public DateTime? LastModificationTime { get; set; }

    public string? CreatorId { get; set; }

    public string? CreatorOrgId { get; set; }

    public DateTime CreationTime { get; set; }

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

    public string ReUser { get; set; }

    public string CrUser { get; set; }

    public string SignUser { get; set; }
}

public class AboutToExpireDto : OrderDto
{
    public string IntervalText { get; set; }

}

public record AboutToExpireListDto : PagedKeywordRequest
{
    /// <summary>
    /// 一级部门
    /// </summary>
    public string? OrgLevelOneName { get; set; }

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

    /// <summary>
    /// 期满时间
    /// </summary>
    public DateTime? ExpiredTimeStart { get; set; }
    public DateTime? ExpiredTimeEnd { get; set; }

    /// <summary>
	/// 归档时间
	/// </summary>
	public DateTime? FiledTimeStart { get; set; }
    public DateTime? FiledTimeEnd { get; set; }

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

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

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

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

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

    /// <summary>
    /// 来电号码
    /// </summary>
    public string? FromPhone { get; set; }

    /// <summary>
    /// 是否为省工单
    /// </summary>
    public bool? IsProvince { get; set; }

    /// <summary>
    /// 工单编码（20220101000001）
    /// </summary>
    public string? No { get; set; }

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

    /// <summary>
    /// 0 全部  1 是  2 否
    /// </summary>
    public int? Delay { get; set; }

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

    /// <summary>
    /// 排序方式 // 0 升序 1 降序
    /// </summary>
    public int? SortRule { get; set; } = 0;
}

public class PublishOrderAllDto
{
    /// <summary>
    /// 工单id
    /// </summary>
    public string OrderId { get; set; }

    /// <summary>
    /// 来电/信人姓名
    /// </summary>
    public string? FromName { get; set; }

    /// <summary>
    /// 联系电话
    /// </summary>
    public string? Contact { get; set; }

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

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

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

    public string? SourceChannelCode { get; set; }

    /// <summary>
    /// 受理类型(咨询、投诉等)
    /// </summary>
    public string? AcceptType { get; set; }

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

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

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

    /// <summary>
    /// 工单状态 0：办理中；1办理完成
    /// </summary>
    public string State { get; set; }

    /// <summary>
    /// 实际办理意见（办理中...or 最终办理意见）
    /// </summary>
    public string ActualOpinion { get; set; }

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

    /// <summary>
    /// 发布时间
    /// </summary>
    public DateTime? PubDate { get; set; }

    /// <summary>
    /// 归档时间
    /// </summary>
    public DateTime? FiledTime { get; set; }
}