using Hotline.Share.Dtos.CallCenter;
using Hotline.Share.Dtos.Settings;
using Hotline.Share.Dtos.Users;
using Hotline.Share.Enums.Order;
using Hotline.Share.Requests;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XF.Utility.EnumExtensions;

namespace Hotline.Share.Dtos.Order
{
    public record CanLinkCallRecordOrderVisitDto : PagedKeywordRequest
    {

    }
    public record QueryOrderVisitDto : PagedKeywordRequest
    {
        public EVisitStateQuery VisitStateQuery { get; set; }

        /// <summary>
        /// 归档方式
        /// </summary>
        public FiledType? FiledType { get; set; }

        /// <summary>
        /// 是否会签
        /// </summary>
        public bool? IsCountersign { get; set; }

        /// <summary>
        /// 回访方式
        /// </summary>
        public EVisitType? VisitType { get; set; }

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

        /// <summary>
        /// 是否只查询自己的待回访工单
        /// </summary>
        public bool? QuerySelf { get; set; }

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

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

        /// <summary>
        /// 是否有效智能回访
        /// </summary>
        public bool? IsEffectiveAiVisit { get; set; }

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

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

        /// <summary>
        /// 语音评价（话务评价）
        /// </summary>
        public List<EVoiceEvaluate> VoiceEvaluate { get; set; } = new();

        /// <summary>
        /// 话务员评价（话务评价）
        /// </summary>
        public List<ESeatEvaluate> SeatEvaluate { get; set; } = new();

        /// <summary>
        /// 部门办件结果
        /// </summary>
        public List<string> OrgProcessingResults { get; set; } = new();

        /// <summary>
        /// 部门办件态度
        /// </summary>
        public List<string> OrgHandledAttitude { get; set; } = new();

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

        /// <summary>
        /// 是否超期
        /// </summary>
        public bool? IsOverTime { get; set; }

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

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

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

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

        /// <summary>
        /// 来电主体
        /// </summary>
        public EIdentityType? IdentityType { get; set; }

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

        /// <summary>
        /// 智能回访结果
        /// </summary>
        public EAiVisitResult? AiVisitResult { get; set; }

        /// <summary>
        /// 是否创建立智能回访任务
        /// </summary>
        public bool? IsAiVisit { get; set; }

        /// <summary>
        /// 工单标签Code
        /// </summary>
        public string? OrderTagCode { get; set; }

        /// <summary>
        /// 是否回访结果修改
        /// </summary>
        public bool? IsUpdate { get; set; }

        /// <summary>
        /// 回访人是否为空
        /// </summary>
        public bool? IsEmployeeNameNull { get; set; }

    }

    public record QueryOrderVisitListDto : QueryOrderVisitDto
    {
        public string? UserID { get; set; }
        public string? UserName { get; set; }
        public string? FieldName { get; set; }
        public string? Title { get; set; }

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

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

        /// <summary>
        /// 接办人
        /// </summary>
        public string? ActualHandlerName { get; set; }

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

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

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

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

        /// <summary>
        /// 区域
        /// </summary>
        public string? AreaCode { get; set; }

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

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

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

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

        /// <summary>
        /// 是否紧急
        /// </summary>
        public bool? IsSecret { get; set; }

        /// <summary>
        /// 是否甄别
        /// </summary>
        public bool? IsScreen { get; set; }
    }

    public record QueryOrderPublishStatisticsAllDto : PagedRequest
    {
        /// <summary>
        /// 开始时间
        /// </summary>
        [Required]
        public DateTime StartTime { get; set; }

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

    public record QueryOrderPublishStatisticsDto : PagedRequest
    {
        /// <summary>
        /// 开始时间
        /// </summary>
        [Required]
        public DateTime StartTime { get; set; }

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

        /// <summary>
        /// 归档方式; 10 = 中心归档, 20 = 部门归档;
        /// 不传查询全部
        /// </summary>
        public EProcessType? ProcessType { get; set; }
    }

    public class QueryOrderVisitQuantity : StartEndTimeDto
    {
        /// <summary>
        /// 访问员
        /// </summary>
        public string? EmployeeName { get; set; }
    }

    public record QueryOrderVisitSourceChannelDto
    {
        /// <summary>
        /// 开始时间
        /// </summary>
        [Required]
        public DateTime StartTime { get; set; }

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

    public record VisitJudgeQueryReq : PagedKeywordRequest
    {
        /// <summary>
        /// 转接号码
        /// </summary>
        public string? TransferPhone { get; set; }
        /// <summary>
        /// 归档类型
        /// </summary>
        public FiledType? FiledType { get; set; }
        /// <summary>
        /// 工单编号
        /// </summary>
        public string? No { get; set; }
        /// <summary>
        /// 工单标题
        /// </summary>
        public string? Title { get; set; }
        /// <summary>
        /// 回访人
        /// </summary>
        public string? VisitUserName { get; set; }
        /// <summary>
        /// 来电号码
        /// </summary>
        public string? FromPhone { get; set; }

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

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

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

        /// <summary>
        /// 受理坐席名字或工号
        /// </summary>
        public string? NameOrNo { 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; }
        /// <summary>
        /// 回访时间
        /// </summary>
        public DateTime? VisitTimeStart { get; set; }

        public DateTime? VisitTimeEnd { get; set; }

        /// <summary>
        /// 评判状态
        /// </summary>
        public EJudgeState? JudgeState { get; set; }

        /// <summary>
        /// 部门扭转
        /// </summary>
        public bool? OrgJudge { get; set; }
        /// <summary>
        /// 坐席扭转
        /// </summary>
        public bool? SeatJudge { get; set; }

        /// <summary>
        /// 是否待扭转
        /// </summary>
        public bool IsIng { get; set; }
    }

    public class JudgeVisitReq
    {
        public List<string> Ids { get; set; }

        /// <summary>
        /// 是否同意
        /// </summary>
        public bool IsAgree { get; set; }

        /// <summary>
        /// 是否
        /// </summary>
        public string? JudgeContent { get; set; }
    }

    public class JudgeVisitRsp
    {
        public int ErrorCount { get; set; }

        public int SuccessCount { get; set; }
    }

    public record VisitDetailListDto : PagedKeywordRequest
    {
        public EVisitStateQuery VisitState { get; set; }
    }

    public record DistributionVisitDto
    {
        public List<string> Ids { get; set; }

        public string UserId { get; set; }
    }

    public record VisitPutThroughDto
    {

        public string id { get; set; }
    }


    public class VisitSmsInDto
    {
        [Required]
        public List<string> Ids { get; set; }
    }

    /// <summary>
    /// 批量保存回访入参
    /// </summary>
    public class VisitBatchInDto
    {
        /// <summary>
        /// 批量保存回访入参
        /// </summary>
        public class VisitIdsBatchInDto
        {
            /// <summary>
            /// 工单Id
            /// </summary>
            [Required(ErrorMessage = "工单Id不能为空")]
            public string OrderId { get; set; }

            /// <summary>
            /// 回访Id
            /// </summary>
            [Required(ErrorMessage = "回访Id不能为空")]
            public string VisitId { get; set; }

            /// <summary>
            /// 工单标题
            /// </summary>
            [Required(ErrorMessage = "工单标题不能为空")]
            public string No { get; set; }
        }

        /// <summary>
        /// 回访Id集合
        /// </summary>
        [Required]
        public List<VisitIdsBatchInDto> Visit { get; set; }

        /// <summary>
        /// 话务员评价（话务评价）
        /// </summary>
        public ESeatEvaluate? SeatEvaluate { get; set; }

        /// <summary>
        /// 部门办件结果
        /// </summary>
        [Required(ErrorMessage = "部门办结结果不能为空")]
        public Kv OrgProcessingResults { get; set; }

        /// <summary>
        /// 部门办件态度
        /// </summary>
        [Required(ErrorMessage = "部门办件态度不能为空")]
        public Kv OrgHandledAttitude { get; set; }

        /// <summary>
        /// 不满意原因
        /// </summary>
        public List<Kv>? OrgNoSatisfiedReason { get; set; }

        /// <summary>
        /// 话务员回访内容
        /// </summary>
        [Required(ErrorMessage = "话务员回访内容不能为空")]
        public string SeatVisitContent { get; set; }

        /// <summary>
        /// 部门回访内容
        /// </summary>
        [Required(ErrorMessage = "部门回访内容不能为空")]
        public string OrgVisitContent { get; set; }
    }

    public class VisitBatchOutDto
    {
        /// <summary>
        /// 总个数
        /// </summary>
        public int TotalCount { get; set; }

        /// <summary>
        /// 成功个数
        /// </summary>
        public int CompleteCount { get; set; }

        /// <summary>
        /// 异常个数
        /// </summary>
        public int ErrorCount { get; set; }

        /// <summary>
        /// 异常信息
        /// </summary>
        public string ErrorMessage { get; set; }
    }

    public record VisitDto
    {
        /// <summary>
        /// 回访主表主键
        /// </summary>
        public string Id { get; set; }

        /// <summary>
        /// 是否接通
        /// </summary>
        public bool IsPutThrough { get; set; }

        /// <summary>
        /// 通话记录ID
        /// </summary>
        public string? CallId { get; set; }

        /// <summary>
        /// 是否重办
        /// </summary>
        public bool IsAgain { get; set; }

        /// <summary>
        /// 部门扭转
        /// </summary>
        public bool? OrgJudge { get; set; }
        /// <summary>
        /// 坐席扭转
        /// </summary>
        public bool? SeatJudge { get; set; }

        /// <summary>
        /// 是否回访结果修改
        /// </summary>
        public bool? IsUpdate { get; set; }

        public List<VisitDetailDto> VisitDetails { get; set; }

        /// <summary>
        /// 是否重办
        /// </summary>
        public bool? IsTransact { get; set; }

        /// <summary>
        /// 重办对象
        /// </summary>
        public OrderReTransactDto? OrderReTransact { get; set; }

        /// <summary>
        /// 是否观察件
        /// </summary>
        public bool? IsObservationPiece { get; set; }


    }

    public record VisitDetailDto
    {
        /// <summary>
        /// Id
        /// </summary>
        public string Id { get; set; }

        /// <summary>
        /// 回访主表ID
        /// </summary>
        public string VisitId { get; set; }

        /// <summary>
        /// 语音评价（话务评价）
        /// </summary>
        public EVoiceEvaluate? VoiceEvaluate { get; set; }

        /// <summary>
        /// 话务员评价（话务评价）
        /// </summary>
        public ESeatEvaluate? SeatEvaluate { get; set; }

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

        /// <summary>
        /// 不满意原因
        /// </summary>
        public List<Kv>? OrgNoSatisfiedReason { get; set; }

        /// <summary>
        /// 部门办件态度
        /// </summary>
        public Kv? OrgHandledAttitude { get; set; }

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

        /// <summary>
        /// 处理结果
        /// </summary>
        public bool? Volved { get; set; }

        /// <summary>
        /// 未解决备注
        /// </summary>
        public string? VolveConent { get; set; }

        /// <summary>
        /// 回访内容
        /// </summary>
        public string? VisitContent { get; set; }

        /// <summary>
        /// 回访部门名称
        /// </summary>
        public string? VisitOrgName { get; set; }

        /// <summary>
        /// 回访部门Code
        /// </summary>
        public string? VisitOrgCode { get; set; }

        /// <summary>
        /// 回访对象类型 10：话务员 20：部门
        /// </summary>
        public EVisitTarget? VisitTarget { get; set; }
    }

    public record OrderVisitAgainListDto : PagedKeywordRequest
    {

    }


    public class AiVisitQueryData
    {
        public string Uid { get; set; }

        public int Status { get; set; }
    }


    public class AddVisitApplyDto
    {
        public string OrderNo { get; set; }

        public string OrderId { get; set; }

        public string VisitReason { get; set; }

        public string OrderVisitId { get; set; }

        public List<string> FileIds { get; set; }
    }

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

        public string? ExaminOpinion { get; set; }

        public bool IsPass { get; set; }
    }

    public class OrderCanVisitAgainDto
    {
        public OrderVisitDto OrderVisit { get; set; }

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

        /// <summary>
        /// 不满意原因
        /// </summary>
        public List<Kv>? OrgNoSatisfiedReason { get; set; }

        /// <summary>
        /// 部门办件态度
        /// </summary>
        public Kv? OrgHandledAttitude { get; set; }

        /// <summary>
        /// 回访部门名称
        /// </summary>
        public string VisitOrgName { get; set; }
    }

    public class VisitApplyDto
    {
        public string? ExaminOpinion { get; set; }

        public DateTime CreationTime { get; set; }

        public string OrderNo { get; set; }

        public string OrderId { get; set; }

        public OrderDto Order { get; set; }

        public string EmployeeId { get; set; }

        public UserDto Employee { get; set; }

        public string VisitReason { get; set; }

        /// <summary>
        /// 源单号
        /// </summary>
        public string OrderVisitId { get; set; }

        public OrderVisitDto OrderVisit { get; set; }

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

        public EVisitApplyState VisitApplyState { get; set; }

        public string VisitApplyStateText => VisitApplyState.GetDescription();

        public string Id { get; set; }

        public string? CreatorId { get; set; }

        public string? CreatorName { get; set; }

        public string? CreatorOrgId { get; set; }

        public string? CreatorOrgName { get; set; }

        public int CreatorOrgLevel { get; set; }

        /// <summary>
        /// 一级部门Id
        /// </summary>
        public string? AreaId { get; set; }
    }

    public record VisitApplyListDto : PagedKeywordRequest
    {
        public EVisitApplyState? VisitApplyState { get; set; }

    }

    public enum EVisitStateQuery
    {
        /// <summary>
        /// 全部
        /// </summary>
        [Description("全部")]
        All = 0,

        /// <summary>
        /// 已回访
        /// </summary>
        [Description("已回访")]
        Visited = 1,

        /// <summary>
        /// 未回访
        /// </summary>
        [Description("未回访")]
        NoVisit = 2,

        /// <summary>
        /// 短信回访中
        /// 逻辑需求(Task_317) : 操作了短信回访的工单，在没有短信结果回复前，回访状态需从“待回访”更新为“短信回访中”
        /// </summary>
        [Description("短信回访中")]
        SMSVisiting = 21,

        /// <summary>
        /// 智能回访待处理
        /// </summary>
        [Description("智能回访待处理")]
        AiVisitWaitForVisit = 23,

        /// <summary>
        /// 短信不满意待回访
        /// 逻辑需求(Task_317) : 若短信回访结果为不满意，回访状态需从“短信回访中”更新为“短信不满意待回访”
        /// </summary>
        [Description("短信不满意待回访")]
        SMSUnsatisfied = 41,

        [Description("未接通")]
        NoPutThrough = 51,

        /// <summary>
        /// 智能回访中
        /// </summary>
        [Description("智能回访中")]
        ChipVoiceVisiting = 61,
    }



    public class OrderVisitQuantityOutDto
    {
        /// <summary>
        /// 回访员
        /// </summary>
        public string EmployeeName { get; set; }

        /// <summary>
        /// 回访员
        /// </summary>
        public string EmployeeId { get; set; }

        /// <summary>
        /// 电话回访量
        /// </summary>
        public int CallVisitCount { get; set; }

        /// <summary>
        /// 默认回访量
        /// </summary>
        public int DefaultVisitCount { get; set; }

        /// <summary>
        /// 短信回访量
        /// </summary>
        public int SmsVisitCount { get; set; }

        /// <summary>
        /// 总回访量
        /// </summary>
        public int TotalVisitCount => SmsVisitCount + DefaultVisitCount + CallVisitCount;
    }
    public class OrderVisitSourceChannelDto
    {
        public int Count { get; set; }

        public string SourceChannel { get; set; }
    }

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

        public OrderDto Order { get; set; }

        /// <summary>
        /// 回访状态
        /// </summary>
        public EVisitState VisitState { get; set; }

        public string VisitStateText => VisitState.GetDescription();

        /// <summary>
        /// 回访方式
        /// </summary>
        public EVisitType? VisitType { get; set; }

        public string VisitTypeText => VisitType?.GetDescription() ?? string.Empty;


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

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

        public string? EmployeeName { get; set; }

        public DateTime CreationTime { get; set; }

        /// <summary>
        /// 是否接通
        /// </summary>
        public bool? IsPutThrough { get; set; }

        /// <summary>
        /// 重办状态
        /// </summary>
        public EAgainState? AgainState { get; set; }

        public string AgainStateText => AgainState?.GetDescription() ?? string.Empty;

        /// <summary>
        /// 回访时间
        /// </summary>
        public DateTime? VisitTime { get; set; }

        /// <summary>
        /// 回访明细
        /// </summary>
        public List<OrderVisitDetailDto> OrderVisitDetails { get; set; }

        /// <summary>
        /// 坐席满意度
        /// </summary>
        public ESeatEvaluate? SeatEvaluate => OrderVisitDetails?.Where(x => x.VisitTarget == EVisitTarget.Seat).FirstOrDefault()?.SeatEvaluate;

        /// <summary>
        /// 坐席满意度
        /// </summary>
        public string? SeatEvaluateText => SeatEvaluate?.GetDescription() ?? string.Empty;

        /// <summary>
        /// 部门满意度
        /// </summary>
        public Kv? OrgProcessingResults => OrderVisitDetails?.Where(x => x.VisitTarget == EVisitTarget.Org).FirstOrDefault()?.OrgProcessingResults;

        /// <summary>
        /// 回复内容
        /// </summary>
        public string? VisitContent => OrderVisitDetails?.Where(x => x.VisitTarget == EVisitTarget.Org).FirstOrDefault()?.VisitContent ?? string.Empty;

        /// <summary>
        /// 可直接访问的通话录音地址
        /// </summary>
        public string? RecordingFileUrl { get; set; }

        public string? RecordingBaseAddress { get; set; }
        public string? RecordingAbsolutePath { get; set; }

        /// <summary>
        /// 渠道为电话时，此字段存在
        /// </summary>
        public string? CallId { get; set; }

        public Kv? NowEvaluate { get; set; }

        /// <summary>
        /// 智能回访录音地址
        /// </summary>
        public string? RecordUrl { get; set; }

        /// <summary>
        /// 部门扭转
        /// </summary>
        public bool? OrgJudge { get; set; }
        /// <summary>
        /// 坐席扭转
        /// </summary>
        public bool? SeatJudge { get; set; }
        /// <summary>
        /// 评判状态
        /// </summary>
        public EJudgeState? JudgeState { get; set; }

        public string? JudgeStateText => JudgeState?.GetDescription() ?? string.Empty;

        /// <summary>
        /// 评判意见
        /// </summary>
        public string? JudgeContent { get; set; }

        /// <summary>
        /// 是否有效智能回访
        /// </summary>
        public bool? IsEffectiveAiVisit { get; set; }
        /// <summary>
        /// 是否有效智能回访
        /// </summary>
        public string IsEffectiveAiVisitText => IsEffectiveAiVisit == true ? "是" : IsEffectiveAiVisit == false ? "否" : "";

        /// <summary>
        /// 工单标签（自贡）
        /// </summary>
        public string? OrderTag => OrderTags != null && OrderTags.Any() ? string.Join(",", OrderTags.Select(x => x.DicDataName)) : string.Empty;

        public string? OrderTagCode { get; set; }

        public List<SystemDicDataOutDto>? OrderTags { get; set; }

        /// <summary>
        /// 是否回访结果修改
        /// </summary>
        public bool? IsUpdate { get; set; }

        /// <summary>
        /// 不满意原因
        /// </summary>
        public List<Kv>? OrgNoSatisfiedReason { get; set; }

        /// <summary>
        /// 回访对象类型 10：话务员 20：部门
        /// </summary>
        public EVisitTarget VisitTarget { get; set; }
    }

    public class OrderVisitDetailDto
    {

        /// <summary>
        /// 回访主表明细ID
        /// </summary>
        public string Id { get; set; }

        /// <summary>
        /// 回访主表ID
        /// </summary>
        public string VisitId { get; set; }


        public OrderVisitDto OrderVisit { get; set; }

        public OrderSecondaryHandlingDto SecondaryHandling { get; set; }

        /// <summary>
        /// 甄别记录
        /// </summary>
        public List<OrderScreenDto> OrderScreens { get; set; }

        public OrderDto Order => OrderVisit != null ? OrderVisit.Order : null;

        /// <summary>
        /// 语音评价（话务评价）
        /// </summary>
        public EVoiceEvaluate? VoiceEvaluate { get; set; }

        public string? VoiceEvaluateText => VoiceEvaluate?.GetDescription();


        /// <summary>
        /// 话务员评价（话务评价）
        /// </summary>
        public ESeatEvaluate? SeatEvaluate { get; set; }

        public string? SeatEvaluateText => SeatEvaluate?.GetDescription();

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

        /// <summary>
        /// 处理结果
        /// </summary>
        public bool? Volved { get; set; }

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

        public string OrgProcessingResultsText => !(OrgProcessingResults is null) ? OrgProcessingResults.Value : "";

        /// <summary>
        /// 不满意原因
        /// </summary>
        public List<Kv>? OrgNoSatisfiedReason { get; set; }

        /// <summary>
        /// 不满意原因字符串
        /// </summary>
        public string OrgNoSatisfiedReasonText => OrgNoSatisfiedReason != null ? string.Join(',', OrgNoSatisfiedReason.Select(d => d.Value)) : "";

        /// <summary>
        /// 部门办件态度
        /// </summary>
        public Kv? OrgHandledAttitude { get; set; }

        /// <summary>
        /// 回访内容
        /// </summary>
        public string? VisitContent { get; set; }

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

        /// <summary>
        /// 回访部门名称
        /// </summary>
        public string VisitOrgName { get; set; }

        /// <summary>
        /// 回访对象类型 10：话务员 20：部门
        /// </summary>
        public EVisitTarget VisitTarget { get; set; }

        /// <summary>
        /// 未解决备注
        /// </summary>
        public string? VolveConent { get; set; }

        /// <summary>
        /// 是否退回
        /// </summary>
        public string ScreenSendBackText => GetScreenSendBack() ? "是" : "否";

        public bool GetScreenSendBack()
        {
            if (OrderScreens != null && OrderScreens.Any())
            {
                if (OrderScreens.First().Status == EScreenStatus.SendBack && OrderScreens.First().SendBackApply)
                {
                    return true;
                }
            }
            return false;
        }
        public bool ScreenSendBack => GetScreenSendBack();

        /// <summary>
        /// 截至甄别时间
        /// </summary>
        public DateTime? ScreenByEndTime { get; set; }

        public bool? IsShowOperate { get; set; }

    }

    /// <summary>
    /// 回访详情的历史记录
    /// </summary>
    public class OrderVisitDetailHistoryDto
    {
        public EVoiceEvaluate? VoiceEvaluate { get; set; }
        public string? VoiceEvaluateTxt => this.VoiceEvaluate?.GetDescription();
        public ESeatEvaluate? SeatEvaluate { get; set; }
        public string? SeatEvaluateTxt => this.SeatEvaluate?.GetDescription();
        public string VisitOrgName { get; set; }
        public Kv? OrgProcessingResults { get; set; }
        public string? orgProcessingResultsValue => this.OrgProcessingResults?.Value;
        public Kv? OrgHandledAttitude { get; set; }
        public string? OrgHandledAttitudeValue => this.OrgHandledAttitude?.Value;
        public string? VisitContent { get; set; }
        public DateTime? VisitTime { get; set; }

        /// <summary>
        /// 通话Id
        /// </summary>
        public string? CallId { get; set; }
    }

    public class DistributionVisitRspDto
    {
        public int SuccessCount { get; set; }

        public int ErrorCount { get; set; }
    }

    public class PublishVisitAllDto
    {
        public OrderDto? Order { get; set; }

        public string Id { get; set; }

        /// <summary>
        /// 回访状态
        /// </summary>
        public EVisitState VisitState { get; set; }

        /// <summary>
        /// 回访方式
        /// </summary>
        public EVisitType? VisitType { get; set; }

        public string? VisitName { get; set; }

        /// <summary>
        /// 回访时间
        /// </summary>
        public DateTime? VisitTime { get; set; }

        /// <summary>
        /// 回访明细
        /// </summary>
        public List<VisitDetailDto> OrderVisitDetails { get; set; }

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


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

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

        /// <summary>
        /// 回访评价方式
        /// </summary>
        public EVisitType? VisitType { get; set; }

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

        /// <summary>
        /// 回访时间
        /// </summary>
        public DateTime? VisitTime { get; set; }

        /// <summary>
        /// 回访评价情况
        /// </summary>
        public string VisitRemark { get; set; }

        /// <summary>
        /// 回访结果满意度
        /// </summary>
        public string SubjectResultSatifyCode { get; set; }

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

        /// <summary>
        /// 工单回访首次结果满意度
        /// </summary>
        public string FirstSatisfactionCode { get; set; }

        /// <summary>
        /// 附件
        /// </summary>
        public string ClientGuid { get; set; }
    }

    public class OrderVisitDetailWebDto
    {
        /// <summary>
        /// 回访明细ID
        /// </summary>
        public string Id { get; set; }
        /// <summary>
        /// 回访对象类型 10：话务员 20：部门
        /// </summary>
        public EVisitTarget VisitTarget { get; set; }

        /// <summary>
        /// 语音评价（话务评价）
        /// </summary>
        public EVoiceEvaluate? VoiceEvaluate { get; set; }

        /// <summary>
        /// 话务员评价（话务评价）
        /// </summary>
        public ESeatEvaluate? SeatEvaluate { get; set; }

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

        /// <summary>
        /// 不满意原因
        /// </summary>
        public List<Kv>? OrgNoSatisfiedReason { get; set; }

        /// <summary>
        /// 部门办件态度
        /// </summary>
        public Kv? OrgHandledAttitude { get; set; }

        /// <summary>
        /// 回访内容
        /// </summary>
        public string? VisitContent { get; set; }

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

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

    }

    public class OrderVisitProvinceDto
    {
        public string ProvinceNo { get; set; }

        public EVisitType VisitType { get; set; }


        public DateTime VisitTime { get; set; }

        public string VisitRemark { get; set; }

        public Kv VisitResult { get; set; }
    }

    /// <summary>
    /// 回访更新事件载荷
    /// </summary>
    public class OrderVisitNotifyDto
    {
        /// <summary>
        /// Id
        /// </summary>
        public string Id { get; set; }

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

        /// <summary>
        /// 回访详情
        /// </summary>
        public List<OrderVisitDetailDto> OrderVisitDetails { get; set; }

        /// <summary>
        /// 回访状态
        /// </summary>
        public EVisitState VisitState { get; set; }

        /// <summary>
        /// 回访方式
        /// </summary>
        public EVisitType? VisitType { get; set; }

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

        /// <summary>
        /// 回访时间
        /// </summary>
        public DateTime? VisitTime { get; set; }

        public string CreatorName { get; set; }

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

    /// <summary>
    /// 修改记录
    /// </summary>
    public class OrderVisitDetailCopyDto
    {
        /// <summary>
        /// 回访信息
        /// </summary>
        public List<OrderVisitDetailDto> OrderVisitDetailDtos { get; set; }

        /// <summary>
        /// 修改记录
        /// </summary>
        public List<OrderVisitDetailDto> OrderVisitDetailCopyDtos { get; set; }


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

        /// <summary>
        /// 创建人
        /// </summary>
        public string? CreatorName { get; set; }
    }
}
