namespace Hotline.Share.Dtos.CallCenter
{
    public class QueryCallsDetailDto
    {
        /// <summary>
        /// 日期
        /// </summary>
        public string Date { get; set; }

        /// <summary>
        /// 时间
        /// </summary>
        public string Hour { get; set; }

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

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

        /// <summary>
        /// 未接秒挂
        /// </summary>
        public int NotAcceptedHang { get; set; }

        /// <summary>
        /// 呼入接通率
        /// </summary>
        public string InConnectionRate => CalcSatisfiedRate(InTotal - NotAcceptedHang, InConnectionQuantity);

        /// <summary>
        /// 呼入总时长
        /// </summary>
        public double TotalDurationIncomingCalls { get; set; }

        /// <summary>
        /// 平均时长
        /// </summary>
        public double AverageDuration => CalcAvg(TotalDurationIncomingCalls, InConnectionQuantity);

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

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

        /// <summary>
        /// 有效接通率
        /// </summary>
        public string EffectiveConnectionRate => CalcSatisfiedRate(InConnectionQuantity, InAvailableAnswer - InHangupImmediateWhenAnswered);

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

        /// <summary>
        /// 超时挂断
        /// </summary>
        public int TimeoutSuspension { get; set; }

        /// <summary>
        /// 按时接通率
        /// </summary>
        public string OnTimeConnectionRate => CalcSatisfiedRate(InConnectionQuantity, InConnectionQuantity - TimeoutConnection - TimeoutSuspension);

        /// <summary>
        /// 队列挂断
        /// </summary>
        public int QueueByeCount { get; set; }

        /// <summary>
        /// IVR挂断
        /// </summary>
        public int IvrByeCount { get; set; }

        /// <summary>
        /// 呼出总量
        /// </summary>
        public int OutTotal { get; set; }

        /// <summary>
        /// 呼出接通量
        /// </summary>
        public int OutConnectionQuantity { get; set; }

        /// <summary>
        /// 呼出接通率
        /// </summary>
        public string OutConnectionRate => CalcSatisfiedRate(OutTotal, OutConnectionQuantity);

        /// <summary>
        /// 计算平均
        /// </summary>
        /// <param name="Count">总数</param>
        /// <param name="Quantity"></param>
        /// <returns></returns>
        public double CalcAvg(double Count, int Quantity)
        {
            if (Count <= 0 || Quantity <= 0)
                return 0;

            return Math.Round((Count / (double)Quantity), 3);
        }

        /// <summary>
        /// 计算满意度
        /// </summary>
        /// <param name="Count">总数</param>
        /// <param name="Quantity"></param>
        /// <returns></returns>
        public string CalcSatisfiedRate(int Count, int Quantity)
        {
            if (Count <= 0 || Quantity <= 0)
                return 0 + "%";

            return Math.Round((Quantity / (double)Count) * 100, 3) + "%";
        }
    }

    public class QueryCallsDetailStatistics
    {

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

        /// <summary>
        /// 呼入总量 (呼入接通 + 挂机量 + 呼入队列挂断)
        /// </summary>
        public int InTotal => InConnectionQuantity + InNotAnswered + NotAcceptedHang;

        /// <summary>
        /// 呼入队列挂断
        /// </summary>
        public int NotAcceptedHang { get; set; }

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

        /// <summary>
        /// 挂机量(呼入 + telno 非空 + 通话时间是0)
        /// </summary>
        public int InNotAnswered { get; set; }

        /// <summary>
        /// 呼入接通率
        /// </summary>
        public string InConnectionRate => CalcSatisfiedRate(InTotal, InConnectionQuantity + InNotAnswered);

        /// <summary>
        /// 呼入IVR挂断
        /// </summary>
        public int IvrByeCount { get; set; }

        /// <summary>
        /// 呼出接通量
        /// </summary>
        public int OutConnectionQuantity { get; set; }

        /// <summary>
        /// 呼出未接通
        /// </summary>
        public int OutNotAnswered { get; set; }

        /// <summary>
        /// 计算满意度
        /// </summary>
        /// <param name="Count">总数</param>
        /// <param name="Quantity"></param>
        /// <returns></returns>
        public string CalcSatisfiedRate(int Count, int Quantity)
        {
            if (Count <= 0 || Quantity <= 0)
                return 0 + "%";

            return Math.Round((Quantity / (double)Count) * 100, 3) + "%";
        }

    }
}
