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.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 VisitState { 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; }
    }

    public record VisitJudgeQueryReq:PagedKeywordRequest
    {
        /// <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 List<string> AcceptTypes { get; set; } = new();

        /// <summary>
        /// 热点分类
        /// </summary>
        public List<string> HotspotIds { get; set; } = new();

        /// <summary>
        /// 接办部门
        /// </summary>
        public List<string> OrgCodes { get; set; } = new();

        /// <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 EmployeeId { 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; }

        public List<VisitDetailDto> VisitDetails { 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,
    }

    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 string 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 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; }
    }

    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; }

        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; }
    }

    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; }
      
    }


    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; }


    }
}
