using Hotline.Share.Enums.CallCenter;
using Hotline.Share.Requests;
using Hotline.Share.Tools;
using System.ComponentModel.DataAnnotations;
using XF.Utility.EnumExtensions;

namespace Hotline.Share.Dtos.CallCenter;

public record BiQueryCallsDto : ReportRequiredPagedRequest
{
    /// <summary>
    /// 线路
    /// </summary>
    public string? Line { get; set; }

    /// <summary>
    /// 查询类型 1：呼入总量明细；2：接通总量明细
    /// </summary>
    public string? TypeCode { get; set; } = "1";
}

public record BiQueryCallsListDto : ReportRequiredPagedRequest
{
    /// <summary>
    /// 用户Id
    /// </summary>
    public string? UserId { get; set; }

    /// <summary>
    /// 用户名称
    /// </summary>
    public string? UserName { get; set; }

    /// <summary>
    /// 字段类型
    /// </summary>
    public string? FieldName { get; set; }
}

public record QueryCallListDto : PagedRequest
{
    public DateTime StartTime { get; set; }
    public DateTime EndTime { get; set; }
    public string Type { get; set; }
    public string Source { get; set; }
    public TimeSpan? StartHourTo { get; set; }

    /// <summary>
    /// 排序字段 
    /// </summary>
    public string? SortField { get; set; }

    /// <summary>
    /// 排序规则  0 升序  1 降序
    /// </summary>
    public int? SortRule { get; set; }
}

public class BiQueryHourCallDto : StartEndTimeDto
{

    public string Source { get; set; }
}

public class BiQueryGateWayDto : StartEndTimeDto
{
    public string Gateway { get; set; }
}

public class StartEndTimeDto
{
    [Required]
    public DateTime StartTime { get; set; }

    [Required]
    public DateTime EndTime { get; set; }
}

public record PagedStartEndTimeDto : PagedRequest
{
    [Required]
    public DateTime StartTime { get; set; }

    [Required]
    public DateTime EndTime { get; set; }
}

public class TotalList<T>
{
    public TotalList()
    {

    }
    public TotalList(List<T> list, T total)
    {
        List = list;
        Total = total;
    }

    public T Total { get; set; }
    public List<T> List { get; set; }
}

public class TotalData<T>
{
    public TotalData()
    {

    }
    public TotalData(List<T> list, int total)
    {
        Data = list;
        Total = total;
    }

    public int Total { get; set; }
    public List<T> Data { get; set; }
}

public record QueryCallsStatisticsDetailInDto : PagedStartEndTimeDto
{
    /// <summary>
    /// 工单编号
    /// </summary>
    public string? OrderNo { get; set; }

    /// <summary>
    /// 主叫
    /// </summary>
    public string? FromNo { get; set; }

    /// <summary>
    /// 被叫
    /// </summary>
    public string? ToNo { get; set; }

    /// <summary>
    /// 分机号码
    /// </summary>
    public string? TelNo { get; set; }

    /// <summary>
    /// 挂断方
    /// </summary>
    public EEndBy? EndBy { get; set; }

    /// <summary>
    /// 上一个页面点击的字段名称
    /// </summary>
    public string? FieldName { get; set; }
}

public class QueryCallsStatisticsDetailOutDto
{
    public string Id { get; set; }
    public string? OrderId { get; set; }

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

    /// <summary>
    /// 工单标题
    /// </summary>
    public string? OrderTitle { get; set; }

    /// <summary>
    /// 主叫
    /// </summary>
    public string FromNo { get; set; }

    /// <summary>
    /// 被叫
    /// </summary>
    public string ToNo { get; set; }

    /// <summary>
    /// 响应分机号
    /// </summary>
    public string TelNo { get; set; }

    /// <summary>
    /// 挂断方
    /// </summary>
    public EEndBy? EndBy { get; set; }

    public string EndByTxt => EndBy.GetDescription();

    /// <summary>
    /// 话务员姓名
    /// </summary>
    public string UserName { get; set; }

    /// <summary>
    /// 分机组id(技能组Id)
    /// </summary>
    public string? GroupId { get; set; }

    /// <summary>
    /// IVR开始时间
    /// </summary>
    public DateTime? BeginIvrTime { get; set; }

    /// <summary>
    /// 接听时间
    /// </summary>
    public DateTime? AnsweredTime { get; set; }

    /// <summary>
    /// 挂机时间
    /// </summary>
    public DateTime EndTime { get; set; }

    /// <summary>
    /// 通话时长(秒)
    /// </summary>
    public int Duration { get; set; }

    /// <summary>
    /// 语音文件路径
    /// </summary>
    public string AudioFile { get; set; }
}


#region 宜宾新话务报表

public class QueryCallDateStatisticsDetailDto
{
    public DateTime? StartTime { get; set; }

    public DateTime? EndTime { get; set; }
}

public class QueryCallDateStatisticsDetailResp
{
    /// <summary>
    /// 日期
    /// </summary>
    public string Date { get; set; }

    /// <summary>
    /// 呼入总量(计算所得)
    /// </summary>
    public int CallInTotal => IvrCallInTotal + PersonCallInCount + EnterpriseCallInCount + GaoXiaoCallInCount + AiCallInCount;
    //public int CallInTotal { get; set; }

    /// <summary>
    /// IVR呼入总量
    /// </summary>
    public int IvrCallInTotal { get; set; }

    /// <summary>
    /// 个人服务呼入总量
    /// </summary>
    public int PersonCallInCount { get; set; }

    /// <summary>
    /// 企业服务呼入总量
    /// </summary>
    public int EnterpriseCallInCount { get; set; }

    /// <summary>
    /// 高效办成一件事总量
    /// </summary>
    public int GaoXiaoCallInCount { get; set; }

    /// <summary>
    /// 智能应答呼入总量
    /// </summary>
    public int AiCallInCount { get; set; }

    /// <summary>
    /// 接通总量(计算所得)
    /// </summary>
    public int PutthroughCount => PersonCallInPutthroughCount + EnterpriseCallInPutthroughCount + GaoXiaoCallInPutthroughCount + AiCallInPutthroughCount;

    /// <summary>
    /// 个人服务接通量
    /// </summary>
    public int PersonCallInPutthroughCount { get; set; }

    /// <summary>
    /// 企业服务接通量
    /// </summary>
    public int EnterpriseCallInPutthroughCount { get; set; }

    /// <summary>
    /// 高效办成一件事接通量
    /// </summary>
    public int GaoXiaoCallInPutthroughCount { get; set; }

    /// <summary>
    /// 智能应答呼入接通量
    /// </summary>
    public int AiCallInPutthroughCount { get; set; }

    /// <summary>
    /// 挂断总量
    /// </summary>
    public int RingOffCount => PersonRingOffCount + EnterpriseRingOffCount + GaoXiaoRingOffCount + IvrRingOffCount;

    /// <summary>
    /// 个人服务挂断总量
    /// </summary>
    public int PersonRingOffCount { get; set; }

    /// <summary>
    /// 企业服务挂断总量
    /// </summary>
    public int EnterpriseRingOffCount { get; set; }

    /// <summary>
    /// 高效办成一件事挂断总量
    /// </summary>
    public int GaoXiaoRingOffCount { get; set; }

    /// <summary>
    /// IVR挂断总量
    /// </summary>
    public int IvrRingOffCount { get; set; }

    /// <summary>
    /// 总体接通率
    /// </summary>
    public double TotalPutthroughRate => PutthroughCount == 0 ? 0 : Math.Round(((double)PutthroughCount / CallInTotal) * 100, 2);

    /// <summary>
    /// 总体接通率（文本）
    /// </summary>
    public string TotalPutthroughRateText => TotalPutthroughRate + "%";

    /// <summary>
    /// 服务接通率
    /// </summary>
    public double ServicePutthorughRate => (PersonCallInCount + EnterpriseCallInCount + GaoXiaoCallInCount + AiCallInCount) == 0 ? 0 : Math.Round(((double)PutthroughCount / (PersonCallInCount + EnterpriseCallInCount + GaoXiaoCallInCount + AiCallInCount)) * 100, 2);

    /// <summary>
    /// 服务接通率（文本）
    /// </summary>
    public string ServicePutthorughRateText => ServicePutthorughRate + "%";

    /// <summary>
    /// 话务接通率
    /// </summary>
    public double CallPutthorughRate => (PersonCallInPutthroughCount + EnterpriseCallInPutthroughCount + GaoXiaoCallInPutthroughCount) == 0 ? 0 : Math.Round(((double)(PersonCallInPutthroughCount + EnterpriseCallInPutthroughCount + GaoXiaoCallInPutthroughCount)) / (PersonCallInCount + EnterpriseCallInCount + GaoXiaoCallInCount) * 100, 2);

    /// <summary>
    /// 话务接通率（文本）
    /// </summary>
    public string CallPutthorughRateText => CallPutthorughRate + "%";
}


public class QueryPersonCallDateStatisticsDetailResp
{
    /// <summary>
    /// 日期
    /// </summary>
    public string Date { get; set; }

    /// <summary>
    /// 个人服务呼入总量
    /// </summary>
    public int PersonCallInCount { get; set; }

    /// <summary>
    /// 个人服务接通量
    /// </summary>
    public int PersonCallInPutthroughCount { get; set; }

    /// <summary>
    /// 个人服务挂断总量
    /// </summary>
    public int PersonRingOffCount => PersonQueueOffCount + PersonWaitOffCount;

    /// <summary>
    /// 个人服务队列挂断
    /// </summary>
    public int PersonQueueOffCount { get; set; }

    /// <summary>
    /// 个人服务等待挂断
    /// </summary>
    public int PersonWaitOffCount { get; set; }

    /// <summary>
    /// 个人服务接通率
    /// </summary>
    public double PersonCallPutthorughRate => PersonCallInPutthroughCount == 0 ? 0 : Math.Round(((double)(PersonCallInPutthroughCount)) / (PersonCallInCount) * 100, 2);

    /// <summary>
    ///  个人服务接通率
    /// </summary>
    public string PersonCallPutthorughRateText => PersonCallPutthorughRate + "%";
}


public class QueryEnterpriseCallDateStatisticsDetailResp
{
    /// <summary>
    /// 日期
    /// </summary>
    public string Date { get; set; }

    /// <summary>
    /// 企业服务呼入总量
    /// </summary>
    public int EnterpriseCallInCount { get; set; }

    /// <summary>
    /// 企业服务接通量
    /// </summary>
    public int EnterpriseCallInPutthroughCount { get; set; }

    /// <summary>
    /// 企业服务挂断总量
    /// </summary>
    public int EnterpriseRingOffCount => EnterpriseQueueOffCount + EnterpriseWaitOffCount;

    /// <summary>
    /// 企业服务队列挂断
    /// </summary>
    public int EnterpriseQueueOffCount { get; set; }

    /// <summary>
    /// 企业服务等待挂断
    /// </summary>
    public int EnterpriseWaitOffCount { get; set; }

    /// <summary>
    /// 企业服务接通率
    /// </summary>
    public double EnterpriseCallPutthorughRate => EnterpriseCallInPutthroughCount == 0 ? 0 : Math.Round(((double)(EnterpriseCallInPutthroughCount)) / (EnterpriseCallInCount) * 100, 2);

    /// <summary>
    ///  个人服务接通率
    /// </summary>
    public string EnterpriseCallPutthorughRateText => EnterpriseCallPutthorughRate + "%";
}

public class QueryGaoXiaoCallDateStatisticsDetailResp
{
    /// <summary>
    /// 日期
    /// </summary>
    public string Date { get; set; }

    /// <summary>
    /// 高效服务呼入总量
    /// </summary>
    public int GaoXiaoCallInCount { get; set; }

    /// <summary>
    /// 高效服务接通量
    /// </summary>
    public int GaoXiaoCallInPutthroughCount { get; set; }

    /// <summary>
    /// 高效服务挂断总量
    /// </summary>
    public int GaoXiaoRingOffCount => GaoXiaoQueueOffCount + GaoXiaoWaitOffCount;

    /// <summary>
    /// 高效服务队列挂断
    /// </summary>
    public int GaoXiaoQueueOffCount { get; set; }

    /// <summary>
    /// 高效服务等待挂断
    /// </summary>
    public int GaoXiaoWaitOffCount { get; set; }

    /// <summary>
    /// 高效服务接通率
    /// </summary>
    public double GaoXiaoCallPutthorughRate => GaoXiaoCallInPutthroughCount == 0 ? 0 : Math.Round(((double)(GaoXiaoCallInPutthroughCount)) / (GaoXiaoCallInCount) * 100, 2);

    /// <summary>
    ///  高效服务接通率
    /// </summary>
    public string GaoXiaoCallPutthorughRateText => GaoXiaoCallPutthorughRate + "%";
}

public class QueryCallOutDateStatisticsDetailResp
{
    /// <summary>
    /// 日期
    /// </summary>
    public string Date { get; set; }

    /// <summary>
    /// 呼出总量
    /// </summary>
    public int CallOutTotal => PersonCallOutCount + EnterpriseCallOutCount + AiVisitCallOutCount + AiCallOutCount;

    /// <summary>
    /// 个人服务呼出总量
    /// </summary>
    public int PersonCallOutCount { get; set; }

    /// <summary>
    /// 企业服务呼出总量
    /// </summary>
    public int EnterpriseCallOutCount { get; set; }

    /// <summary>
    /// 智能回访呼出总量
    /// </summary>
    public int AiVisitCallOutCount { get; set; }

    /// <summary>
    /// 智能外呼呼出总量
    /// </summary>
    public int AiCallOutCount { get; set; }

    /// <summary>
    /// 呼出接通数
    /// </summary>
    public int CallOutPutthroughCount => PersonCallOutPutthroughCount + EnterpriseCallOutPutthroughCount + AiVisitCallOutPutthroughCount + AiCallOutPutthroughCount;

    /// <summary>
    /// 个人服务呼出接通数
    /// </summary>
    public int PersonCallOutPutthroughCount { get; set; }

    /// <summary>
    /// 企业服务呼出接通数
    /// </summary>
    public int EnterpriseCallOutPutthroughCount { get; set; }

    /// <summary>
    /// 智能回访呼出接通数
    /// </summary>
    public int AiVisitCallOutPutthroughCount { get; set; }

    /// <summary>
    /// 智能外呼呼出接通数
    /// </summary>
    public int AiCallOutPutthroughCount { get; set; }

    /// <summary>
    /// 呼出接通率
    /// </summary>
    public double CallOutPutthroughRate => CallOutTotal == 0 ? 0 : Math.Round(((double)CallOutPutthroughCount / CallOutTotal) * 100, 2);

    public string CallOutPutthroughRateText => CallOutPutthroughRate + "%";

    /// <summary>
    /// 个人服务呼出接通率
    /// </summary>
    public double PersonCallOutPutthroughRate => PersonCallOutCount == 0 ? 0 : Math.Round(((double)PersonCallOutPutthroughCount / PersonCallOutCount) * 100, 2);

    public string PersonCallOutPutthroughRateText => PersonCallOutPutthroughRate + "%";

    /// <summary>
    /// 企业服务呼出接通率
    /// </summary>
    public double EnterpriseCallOutPutthroughRate => EnterpriseCallOutCount == 0 ? 0 : Math.Round(((double)EnterpriseCallOutPutthroughCount / EnterpriseCallOutCount) * 100, 2);


    public string EnterpriseCallOutPutthroughRateText => EnterpriseCallOutPutthroughRate + "%";

    /// <summary>
    /// 智能回访呼出接通率
    /// </summary>
    public double AiVisitCallOutPutthroughRate => AiVisitCallOutCount == 0 ? 0 : Math.Round(((double)AiVisitCallOutPutthroughCount / AiVisitCallOutCount) * 100, 2);

    public string AiVisitCallOutPutthroughRatetext => AiVisitCallOutPutthroughRate + "%";

    /// <summary>
    /// 智能外呼呼出接通率
    /// </summary>
    public double AiCallOutPutthroughRate => AiCallOutCount == 0 ? 0 : Math.Round(((double)AiCallOutPutthroughCount / AiCallOutCount) * 100, 2);

    public string AiCallOutPutthroughRateText => AiCallOutPutthroughRate + "%";
}


public class QuerySeatMonthCallResp
{
    /// <summary>
    /// 坐席姓名
    /// </summary>
    public string Name { get; set; }

    /// <summary>
    /// 用户ID
    /// </summary>
    public string UserId { get; set; }

    /// <summary>
    /// 呼入总量
    /// </summary>
    public int InTotal => InAnswered + InHanguped;

    /// <summary>
    /// 呼入接通量
    /// </summary>
    public int InAnswered { get; set; }

    /// <summary>
    /// 有效接通量
    /// </summary>
    public int InAvailableAnswer { get; set; }

    /// <summary>
    /// 呼入接通秒挂
    /// </summary>
    public int InHangupImmediateWhenAnswered { get; set; }

    /// <summary>
    /// 超时接通量
    /// </summary>
    public int OverTimeImmediate { get; set; }

    /// <summary>
    /// 按时接通量
    /// </summary>
    public int InTimeImmediate { get; set; }

    /// <summary>
    /// 呼入未接通总量
    /// </summary>
    public int InHanguped { get; set; }

    /// <summary>
    /// 未接通秒挂量
    /// </summary>
    public int InHangupImmediate { get; set; }

    /// <summary>
    /// 超时未接通量
    /// </summary>
    public int OverTimeInHanguped { get; set; }

    /// <summary>
    /// 呼入接通率
    /// </summary>
    public double InAnsweredRate => InTotal > 0 ? Math.Round(((double)InAnswered / (double)InTotal) * 100, digits: 2) : 0;

    /// <summary>
    /// 呼入接通率(显示)
    /// </summary>
    public string InAnsweredRateString => this.InAnsweredRate + "%";

}

public class QuerySeatMonthCallRequest
{
    /// <summary>
    /// 振铃开始时间开始
    /// </summary>
    public DateTime? StartTime { get; set; }

    /// <summary>
    /// 振铃开始时间结束
    /// </summary>
    public DateTime? EndTime { get; set; }

    /// <summary>
    /// 员工ID
    /// </summary>
    public string? EmpId { get; set; }
}


public record QuerySeatMonthCallDetailRequest : PagedRequest
{
    /// <summary>
    /// 坐席ID
    /// </summary>
    public string? EmpId { get; set; }

    /// <summary>
    /// 主叫
    /// </summary>
    public string? Cpn { get; set; }

    /// <summary>
    /// 被叫
    /// </summary>
    public string? Cdpn { get; set; }

    /// <summary>
    /// 分机号
    /// </summary>
    public string? TelNo { get; set; }

    /// <summary>
    /// 接通时间开始
    /// </summary>
    public DateTime? AnsweredStartTime { get; set; }

    /// <summary>
    /// 接通时间结束
    /// </summary>
    public DateTime? AnsweredEndTime { get; set; }

    /// <summary>
    /// 振铃时间开始
    /// </summary>
    public DateTime? RingStartTime { get; set; }

    /// <summary>
    /// 振铃时间结束
    /// </summary>
    public DateTime? RingEndTime { get; set; }

    /// <summary>
    /// 振铃结束时间开始
    /// </summary>
    public DateTime? EndRingStartTime { get; set; }

    /// <summary>
    /// 振铃结束时间结束
    /// </summary>
    public DateTime? EndRingEndTime { get; set; }

    /// <summary>
    /// 点数进入明细类型（1：呼入接通总量 2：有效接通量 3：接通秒挂量 4：超时接通量 5:按时接通量 6：呼入未接通总量 7：未接通秒挂量 8：超时未接通量）
    /// </summary>
    public int? QueryType { get; set; }
}

public class QuerySeatMonthCallDetailResp
{
    /// <summary>
    /// 主叫
    /// </summary>
    public string Cpn { get; set; }

    /// <summary>
    /// 被叫
    /// </summary>
    public string Cdpn { get; set; }

    /// <summary>
    /// 振铃开始时间
    /// </summary>
    public DateTime? RingTimeBegin { get; set; }

    /// <summary>
    /// 振铃结束时间
    /// </summary>
    public DateTime? RingTimeEnd { get; set; }

    /// <summary>
    /// 接通时间
    /// </summary>
    public DateTime? AnsweredTime { get; set; }

    /// <summary>
    /// 响应分机
    /// </summary>
    public string? TelNo { get; set; }

    /// <summary>
    /// 坐席名称
    /// </summary>
    public string? SeatName { get; set; }
}
#endregion