using Hotline.Share.Dtos.Order;
using Hotline.Share.Enums.Ai;
using Hotline.Share.Enums.Order;
using Hotline.Share.Requests;
using Microsoft.VisualBasic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XF.Utility.EnumExtensions;

namespace Hotline.Share.Dtos.Ai
{
    public record AiCallOutDetailListRequest : PagedRequest
    {
        public string Id { get; set; }

        public string? OuterNo { get; set; }

        public string? Name { get; set; }

        public EAiCallOutState? AiCallOutState { get; set; }
    }


    public class AiCallOutDetailListRep
    {
        public string OuterNo { get; set; }

        public string Name { get; set; }

        public DateTime? CallOutTime { get; set; }

        /// <summary>
        /// 是否成功
        /// </summary>
        public bool? IsSuccess { get; set; }

        public EAiCallOutState AiCallOutState { get; set; }

        public string AiCallOutStateText => AiCallOutState.GetDescription();
    }


    public record AiCallOutListRequest : PagedRequest
    {
        public string TaskName { get; set; }

        public EAiCallOutTaskState? AiCallOutTaskState { get; set; }

        public DateTime? StartTime { get; set; }

        public DateTime? EndTime { get; set; }

    }

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

        public string TaskName { get; set; }

        public EAiCallOutTaskState AiCallOutTaskState { get; set; }

        public string AiCallOutTaskStateText => AiCallOutTaskState.GetDescription();

        /// <summary>
        /// 批次上报结果ID
        /// </summary>
        public string? BatchUid { get; set; }

        public string CallOutTemplateId { get; set; }

        public string CallOutTemplateName { get; set; }

        /// <summary>
        /// 应回访数量
        /// </summary>
        public int HasVisitCount { get; set; }

        /// <summary>
        /// 已回访成功数量
        /// </summary>
        public int VisitedCount { get; set; }

        /// <summary>
        /// 已回访失败数量
        /// </summary>
        public int VisitedFailCount { get; set; }

        /// <summary>
        /// 节日禁呼 0：否 1：是
        /// </summary>
        public int FestivalBan { get; set; }

        public DateTime BeginTime { get; set; }

        public DateTime EndTime { get; set; }

        public DateTime CreationTime { get; set; }

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

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


    public class CallOutTemplateDto
    {
        public string TemplateName { get; set; }

        public string TemplateContent { get; set; }
    }

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

        public string TemplateName { get; set; }
    }

    public class UpdateCallOutTemplateDto : CallOutTemplateDto
    {
        public string Id { get; set; }
    }

    public record AiCallOutTemplateQueryRequest : PagedRequest
    {
        public string TemplateName { get; set; }

        public DateTime? StartTime { get; set; }

        public DateTime? EndTime { get; set; }
    }

    public record AiCallOutTemplateQueryRep
    {
        public string Id { get; set; }

        public string TemplateContent { get; set; }

        /// <summary>
        /// 模板名称
        /// </summary>
        public string TemplateName { get; set; }
        /// <summary>
        /// 外呼任务数
        /// </summary>
        public int CallOutTaskCount { get; set; }

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

        /// <summary>
        /// 是否启用
        /// </summary>
        public bool IsEnable { get; set; }

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

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



    public class AiVisitBackDto
    {
        public string BatchUid { get; set; }

        public string BatchName { get; set; }

        public string SceneUid { get; set; }

        public string SenceName { get; set; }

        public string TaskUid { get; set; }

        public string CalledNumber { get; set; }
        /// <summary>
        /// 任务状态( 1 :待执行、2 :暂停中、3 :执行中、4 :失效、5 :呼叫失败 、6：已结束（完成或取消）)
        /// </summary>
        public int TaskStatus { get; set; }

        public int? CallTimes { get; set; }

        public List<CallRecordDto> CallRecordList { get; set; }
    }

    public class CallRecordDto
    {
        public int CallNo { get; set; }

        //public DateTime? CallTime { get; set; }
        public string? CallTime { get; set; }

        /// <summary>
        /// 呼叫状态(1:呼叫中、2:完成、3:呼叫失败)
        /// </summary>
        public int? CallStatus { get; set; } = 3;

        public string? RecordUrl { get; set; }

        /// <summary>
        /// 回访结果 (1成功、2:不涉及、3:失败)
        /// </summary>
        public int ReturnVisit { get; set; }

        public List<QuestionnaireResult> QuestionnaireResult { get; set; }

        /// <summary>
        /// 不满意原因
        /// </summary>
        public Dictionary<string, string> SceneVariable { get; set; }

        /// <summary>
        /// 语音段列表信息
        /// </summary>
        //public List<SentenceListDto> SentenceList { get; set; }
    }

    public class SentenceListDto
    {
        /// <summary>
        /// 序号
        /// </summary>
        public int Index { get; set; }
        /// <summary>
        /// 开始时间（毫秒）
        /// </summary>
        public int StartTime { get; set; }

        /// <summary>
        /// 结束时间（毫秒）
        /// </summary>
        public int EndTime { get; set; }

        /// <summary>
        /// 角色（机器人:agent，用户:user，未知:unknown）
        /// </summary>
        public string Role { get; set; }

        /// <summary>
        /// 性别（未知:unknow，男:male，女:female）
        /// </summary>
        public string Gender { get; set; }

        /// <summary>
        /// 文本
        /// </summary>
        public string Text { get; set; }

        /// <summary>
        /// 人工编译后文本
        /// </summary>
        public string CorrectText { get; set; }

        /// <summary>
        /// 置信分数（本词条的可信度[0-65535], 分值越高，越可信）
        /// </summary>
        public string Score { get; set; }

        /// <summary>
        /// 语速
        /// </summary>
        public string Speed { get; set; }

        /// <summary>
        /// 最大音量
        /// </summary>
        public string MaxVolume { get; set; }

        /// <summary>
        /// 平均音量
        /// </summary>
        public string AvgVolume { get; set; }
    }

    public class QuestionnaireResult
    {
        public string QuestionId { get; set; }

        public string QuestionChoice { get; set; }

        public string QuestionResult { get; set; }
    }


    public record AiVisitListDto : PagedKeywordRequest
    {
        public EAiOrderVisitTaskState? AiOrderVisitTaskState { get; set; }

        /// <summary>
        /// 智能回访开始时间开始
        /// </summary>
        public DateTime? AiVisitTimeBeginStart { get; set; }

        /// <summary>
        /// 智能回访开始时间结束
        /// </summary>
        public DateTime? AiVisitTimeBeginEnd { get; set; }

        /// <summary>
        /// 智能回访结束时间开始
        /// </summary>
        public DateTime? AiVisitTimeEndStart { get; set; }

        /// <summary>
        /// 智能回访结束时间结束
        /// </summary>
        public DateTime? AiVisitTimeEndEnd { get; set; }

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

    public record AiVisitDetailListDto : PagedKeywordRequest
    {
        public string Id { get; set; }

        public EAiOrderVisitState? AiOrderVisitState { get; set; }
    }

    public class AiOrderVisitDto
    {
        public string Id { get; set; }
        public string Name { get; set; }

        public DateTime BeginTime { get; set; }

        public DateTime EndTime { get; set; }

        public EAiOrderVisitTaskState TaskState { get; set; }

        public string TaskStateText => TaskState.GetDescription();

        /// <summary>
        /// 批次上报结果ID
        /// </summary>
        public string? BatchUid { get; set; }


        /// <summary>
        /// 节日禁呼 0：否 1：是
        /// </summary>
        public int FestivalBan { get; set; }

        /// <summary>
        /// 外呼规则类型 1：自定义 2：：使用现有规则
        /// </summary>
        public int RuleType { get; set; }

        /// <summary>
        /// 现有外呼规则ID
        /// </summary>
        public string RuleUid { get; set; }

        /// <summary>
        /// 应回访数量
        /// </summary>
        public int HasVisitCount { get; set; }

        /// <summary>
        /// 已回访成功数量
        /// </summary>
        public int VisitedCount { get; set; }

        /// <summary>
        /// 已回访失败数量
        /// </summary>
        public int VisitedFailCount { get; set; }

        public DateTime CreationTime { get; set; }

        public string? CreatorName { get; set; }
    }

    public class AiOrderVisitDetailDto
    {
        /// <summary>
        /// 主表ID
        /// </summary>
        public string AiOrderVisitId { get; set; }
        /// <summary>
        /// 工单ID
        /// </summary>
        public string OrderId { get; set; }

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

        /// <summary>
        /// 姓名
        /// </summary>
        public string FromName { get; set; }

        /// <summary>
        /// 来电/信人性别
        /// </summary>
        public EGender FromGender { get; set; }

        /// <summary>
        /// 来电/信人性别
        /// </summary>
        public string FromGenderText => FromGender.GetDescription();

        /// <summary>
        /// 工单开始时间(受理/接办时间=流程开启时间)
        /// </summary>
        public DateTime? StartTime { get; set; }

        /// <summary>
        /// 归档时间（暂为流程结束时间，因流程结束自动归档）
        /// </summary>
        public DateTime? FiledTime { get; set; }

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

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

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

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

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

        /// <summary>
        /// 工单
        /// </summary>
        public OrderDto Order { get; set; }
        /// <summary>
        /// 工单回访主表ID
        /// </summary>
        public string OrderVisitId { get; set; }
        /// <summary>
        /// 工单
        /// </summary>
        public OrderVisitDto OrderVisit { get; set; }

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

        /// <summary>
        /// 外呼电话
        /// </summary>
        public string OuterNo { get; set; }

        public EAiOrderVisitState AiOrderVisitState { get; set; }

        public string AiOrderVisitStateText => AiOrderVisitState.GetDescription();

        /// <summary>
        /// 批此上传成功后任务ID
        /// </summary>
        public string? TaskUid { get; set; }

        /// <summary>
        /// 是否成功
        /// </summary>
        public bool? IsSuccess { get; set; }
        /// <summary>
        /// 是否成功
        /// </summary>
        public string? IsSuccessText { get; set; }

        /// <summary>
        /// 重呼次数
        /// </summary>
        public int CallTimes { get; set; }

        /// <summary>
        /// 最新外呼时间
        /// </summary>
        public DateTime? CallTime { get; set; }
    }

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

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

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

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



    public class AddAiVisitDto
    {
        public string Name { get; set; }

        public DateTime BeginTime { get; set; }

        public DateTime EndTime { get; set; }

        /// <summary>
        /// 节日禁呼 0：否 1：是
        /// </summary>
        public int FestivalBan { get; set; }

        public List<AddAiOrderVisitDetailDto> AiOrderVisitDetails { get; set; }
    }

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

        /// <summary>
        /// 1 :智能回访  2：批量外呼
        /// </summary>
        public int TypeId { get; set; }
    }


    public class AddAiCallOutRequest
    {
        public string TaskName { get; set; }

        public DateTime BeginTime { get; set; }

        public DateTime EndTime { get; set; }
        /// <summary>
        /// 模板ID
        /// </summary>
        public string CallOutTemplateId { get; set; }
        /// <summary>
        /// 节日禁呼 0：否 1：是
        /// </summary>
        public int FestivalBan { get; set; }

        public List<AddAiCallOutTaskDetailDto> AddAiCallOutTaskDetailDtos { get; set; }
    }

    public class AddAiCallOutTaskDetailDto
    {
        public string OuterNo { get; set; }

        public string Name { get; set; }
    }

    public class AddAiOrderVisitDetailDto
    {
        /// <summary>
        /// 工单ID
        /// </summary>
        public string OrderId { get; set; }
        /// <summary>
        /// 工单回访主表ID
        /// </summary>
        public string OrderVisitId { get; set; }

        /// <summary>
        /// 外呼电话
        /// </summary>
        public string OuterNo { get; set; }
    }
}
