
using Hotline.Orders;
using Hotline.Share.Enums.CallCenter;
using SqlSugar;
using XF.Domain.Repository;
using XF.Utility.SequentialId;

namespace Hotline.CallCenter.Calls
{
    [SugarIndex("index_call_callid", nameof(TrCallRecord.OtherAccept), OrderByType.Asc)]
    public class TrCallRecord : CreationEntity
    {
        /// <summary>
        /// IPPBX用户名
        /// </summary>
        public string? User { get; set; }

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

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

        /// <summary>
        /// 呼叫方向
        /// </summary>
        public ECallDirection CallDirection { get; set; }
        /// <summary>
        /// 挂断方
        /// </summary>
        public EEndBy? EndBy { get; set; }

        /// <summary>
        /// 转接分机号
        /// </summary>
        public string? AgentTransferNumber { get; set; }

        /// <summary>
        /// 坐席侧通话流水，无坐席参与则为手机侧通话流水
        /// </summary>
        public string? CallAccept { get; set; }
        /// <summary>
        /// 主叫
        /// </summary>
        public string CPN { get; set; }
        /// <summary>
        /// 主叫名称
        /// </summary>
        public string? CPNName { get; set; }
        /// <summary>
        /// 被叫
        /// </summary>
        public string CDPN { get; set; }
        /// <summary>
        /// 分机号
        /// </summary>
        public string? TelNo { get; set; }
        public string? UserId { get; set; }
        public string? UserName { get; set; }
        public string? StaffNo { get; set; }
        /// <summary>
        /// 通话录音绝对路径
        /// </summary>
        public string? RecordingFileName { get; set; }
        /// <summary>
        /// 通话创建时间
        /// </summary>
        public DateTime CreatedTime { get; set; }
        /// <summary>
        /// 接通时间
        /// </summary>
        public DateTime? AnsweredTime { get; set; }
        /// <summary>
        /// 挂机时间
        /// </summary>
        public DateTime OverTime { get; set; }
        /// <summary>
        /// 线路号
        /// </summary>
        public string? Gateway { get; set; }
        /// <summary>
        /// 呼出时自定义的内容
        /// </summary>
        public string? OtherStr { get; set; }
        /// <summary>
        /// 手机侧通话流水，无坐席参与则为空
        /// </summary>
        public string? OtherAccept { get; set; }
        /// <summary>
        /// 状态码，语音信箱：999/其他：16
        /// </summary>
        public string? Status { get; set; }
        /// <summary>
        /// IVR开始时间
        /// </summary>
        public DateTime? BeginIvrTime { get; set; }
        /// <summary>
        /// IVR结束时间
        /// </summary>
        public DateTime? EndIvrTime { get; set; }
        /// <summary>
        /// 开始等待时间
        /// </summary>
        public DateTime? BeginQueueTime { get; set; }
        /// <summary>
        /// 结束等待时间
        /// </summary>
        public DateTime? EndQueueTime { get; set; }
        /// <summary>
        /// 开始振铃时间
        /// </summary>
        public DateTime? BeginRingTime { get; set; }
        /// <summary>
        /// 结束振铃时间
        /// </summary>
        public DateTime? EndRingTimg { get; set; }
        /// <summary>
        /// 队列ID
        /// </summary>
        public string? OlaQueue { get; set; }
        /// <summary>
        /// 批量外呼流水
        /// </summary>
        public string? BatchAccept { get; set; }
        /// <summary>
        /// IVR按键信息
        /// </summary>
        public string? IvrDtmf { get; set; }
        /// <summary>
        /// IVR按键对应动作，需解码
        /// </summary>
        public string? DtmfType { get; set; }

        /// <summary>
        /// 通话状态
        /// </summary>
        public EOnState OnState { get; set; }

        #region 自定义字段
        /// <summary>
        /// 通话时长（挂机时间-接通时间）
        /// </summary>
        [SugarColumn(DefaultValue = "0")]
        public int Duration { get; set; }

        /// <summary>
        /// 振铃时长（振铃结束时间-振铃开始时间）
        /// </summary>
        [SugarColumn(DefaultValue = "0")]
        public int RingTimes { get; set; }

        /// <summary>
        /// 排队时长（排队结束时间-排队开始时间）
        /// </summary>
        [SugarColumn(DefaultValue = "0")]
        public int QueueTims { get; set; }

        public ECallOrderType? CallOrderType { get; set; }

        /// <summary>
        /// 外部ID
        /// </summary>
        public string? ExternalId { get; set; }

        /// <summary>
        /// 工单
        /// </summary>
        [Navigate(NavigateType.OneToOne, nameof(ExternalId))]
        public Order? Order { get; set; }

        /// <summary>
        /// 呼入号码类型
        /// </summary>
        public EPhoneTypes? PhoneTypes { get; set; }

        /// <summary>
        /// 归属地
        /// </summary>
        public string? MobileAreaName { get; set; }

        /// <summary>
        /// 运营商
        /// </summary>
        public string? OFlag { get; set; }

        /// <summary>
        /// 卡类型
        /// </summary>
        public string? OperatorName { get; set; }

        /// <summary>
        /// 转写内容
        /// </summary>
        [SugarColumn(ColumnDataType = "varchar(8000)")]
		public string? TransliterationContent { get; set; }

        /// <summary>
        /// 转写状态
        /// </summary>
        [SugarColumn(DefaultValue ="0")]
        public ECallTransliterationState TransliterationState { get; set; }

        /// <summary>
        /// 转写id  涉及转写失败后再次推送  id需要更换
        /// </summary>
        public string? TransliterationId { get; set; }

        public void InitTransliterationId() => TransliterationId = SequentialStringGenerator.Create();

        /// <summary>
        /// 敏感标签
        /// </summary>
        [SugarColumn(ColumnDataType = "json", IsJson = true, IsNullable = true, ColumnDescription = "敏感标签")]
        public List<string>? Sensitive { get; set; }
        #endregion

    }
}
