using DataSharing.Share.Enums;
using XF.Utility.EnumExtensions;

namespace DataSharing.Share.Dtos.HotlineWeb
{
    public class DsSendTaskDto
    {
        /// <summary>
        /// ID
        /// </summary>
        public string Id { get; set; }

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

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

        /// <summary>
        /// 最近一次推送时间
        /// </summary>
        public DateTime? LastTime { get; set; }

        /// <summary>
        /// 推送次数
        /// </summary>
        public int SendTimes { get; set; }

        /// <summary>
        /// 平台名称
        /// </summary>
        public EPlatformSource PlatformSource { get; set; } = EPlatformSource.Province;
        public string PlatformSourceText => PlatformSource.GetDescription();

        /// <summary>
        /// 任务类型
        /// addOrder, expiredTimeChanged...
        /// </summary>
        public string TaskType { get; set; }

        /// <summary>
        /// 请求方式
        /// </summary>
        public string HttpMethod { get; set; }

        /// <summary>
        /// 请求地址
        /// </summary>
        public string Path { get; set; }
        public string PathText => GetName();

        /// <summary>
        /// 请求参数
        /// </summary>
        public string Request { get; set; }

        /// <summary>
        /// 请求端口，省推送必填，协同或者汇聚
        /// </summary>
        public EPathType? PathType { get; set; } = EPathType.Other;

        /// <summary>
        /// 生成时间（保存工单创建时间或者通话记录生成时间）
        /// </summary>
        public DateTime? GenerationTime { get; set; }

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

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public string GetName()
        {
            string name = "";
            switch (Path)
            {
                case "get_case_back_apply":
                    name = "业务协同-退回申请接口";
                    break;
                case "send_supervise_process_info":
                    name = "业务协同-服务工单督办过程接口";
                    break;
                case "send_supervise_result_info":
                    name = "业务协同-服务工单督办结果接口";
                    break;
                case "screen_case_info_send":
                    name = "业务协同-工单发起甄别接口";
                    break;
                case "delay_case_info_send":
                    name = "业务协同-服务工单申请延时接口";
                    break;
                case "submit_case_info":
                    name = "业务汇聚-服务工单受理接口";
                    break;
                case "submit_case_record":
                    name = "业务汇聚-电话记录";
                    break;
                case "get_case_process_receive":
                    name = "业务协同-服务工单交办处理过程接口";
                    break;
                case "submit_case_process":
                    name = "业务汇聚-服务工单处理过程接口";
                    break;
                case "submit_case_total":
                    name = "业务汇聚-统计数据接口";
                    break;
                case "supply_case_info_send":
                    name = "业务协同-上报补充诉求接口";
                    break;
                case "revoke_case_info":
                    name = "业务协同-服务工单撤单接口";
                    break;
                case "remind_case_info":
                    name = "业务协同-服务工单催单接口";
                    break;
                case "get_case_result_receive":
                    name = "业务协同-服务工单交办处理结果接口";
                    break;
                case "zmhd_case_info_public":
                    name = "业务协同-政民互动提交公开";
                    break;
                case "get_knowledge_info_send":
                    name = "业务协同-知识库上报接口";
                    break;
                case "get_knowledge_info_update":
                    name = "业务协同-知识库变更接口";
                    break;
                case "get_knowledge_info_abandon":
                    name = "业务协同-知识库下架接口";
                    break;
                case "sendrealtimestatus":
                    name = "实时服务上报接口";
                    break;
                case "get_visit_info_receive":
                    name = "业务协同-服务工单交办评价接口";
                    break;
                case "submit_visit_info":
                    name = "业务汇聚-服务工单回访评价接口";
                    break;
                case "submit_case_result":
                    name = "业务汇聚-服务工单处理结果接口";
                    break;
                case "submit_case_extends":
                    name = "业务汇聚-服务工单拓展信息接口";
                    break;
                case "send_case_info":
                    name = "业务协同-服务工单上报";
                    break;
                case "get_case_material_info":
                    name = "业务汇聚-材料接口";
                    break;
                default:
                    break;
            }

            return name;
        }

    }

    /// <summary>
    /// 待推送
    /// </summary>
    public class DsWaitSendTaskDto : DsSendTaskDto
    {
        /// <summary>
        /// 数据状态 
        /// </summary>
        public EWaitSendTaskState State { get; set; } = EWaitSendTaskState.WaitPush;

        public string StateText => State.GetDescription();
    }

    /// <summary>
    /// 已推送数据
    /// </summary>
    public class DsEndSendTaskDto : DsSendTaskDto
    {
        /// <summary>
        /// 期满时间
        /// </summary>
        public DateTime? ExpiredTime { get; set; }

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

        /// <summary>
        /// 是否超期
        /// </summary>
        public string? IsOverdueText => CalcIsOverdue();

        /// <summary>
        /// 推送状态
        /// </summary>
        public ESendTaskState IsSuccess { get; set; } = ESendTaskState.WaitPush;

        public string IsSuccesseText => IsSuccess.GetDescription();

        /// <summary>
        /// 计算是否超期
        /// </summary>
        /// <returns></returns>
        public string CalcIsOverdue()
        {
            //计算是否超期
            if (ExpiredTime.HasValue)
            {
                if (FiledTime.HasValue)
                    return FiledTime > ExpiredTime ? "是" : "否";
                else
                    return DateTime.Now > ExpiredTime ? "是" : "否";
            }
            return "";
        }
    }
}
