using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hotline.Share.Dtos.CallCenter
{
    public class TrCallHourDto
    {
        //public DateTime Dates { get; set; }

        public int Hour { get; set; }

        public string HourTo { get; set; }

        public string StartHourTo { get; set; }

        public string EndHourTo { get; set; }

        public DateTime DateTimeTo { get; set; }

        /// <summary>
        /// 总计
        /// </summary>
        public int Count => EffectiveCount + ConnectByeCount + NoConnectByeCount + QueueByeCount + IvrByeCount;

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

        /// <summary>
        /// 接通秒挂
        /// </summary>
        public int ConnectByeCount { get; set; }

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

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

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

    public class CallHotLineDto
    {
        /// <summary>
        /// 热线号
        /// </summary>
        public string GateWay { get; set; }
        /// <summary>
        /// 呼入
        /// </summary>
        public int CallInCount { get; set; }

        /// <summary>
        /// 接通
        /// </summary>
        public int ConnectCount { get; set; }

        /// <summary>
        /// 未接通秒挂
        /// </summary>
        public int NoConnectByeCount { get; set; }
        /// <summary>
        /// 接通率
        /// </summary>
        public double CallInConnectRate => CalcCallInConnectRate();


        public double CalcCallInConnectRate()
        {
            if (CallInCount != 0 && ConnectCount != 0)
            {
                return Math.Round((ConnectCount / (double)CallInCount) * 100, 2);
            }
            return 0;
        }


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

        /// <summary>
        /// 平均时长
        /// </summary>
        public double AveDuration => CalcAveDuration();

        public double CalcAveDuration()
        {
            if ((EffectiveCount + ConnectByeCount) != 0 && DurationSum != 0)
            {
                return Math.Round((double)DurationSum / (EffectiveCount + ConnectByeCount), 1);
            }
            return 0;
        }


        /// <summary>
        /// 通话时总长
        /// </summary>
        public double DurationSum { get; set; }

        /// <summary>
        /// 接通秒挂
        /// </summary>
        public int ConnectByeCount { get; set; }

        /// <summary>
        /// 及时应答数
        /// </summary>
        public int TimelyAnswerCount { get; set; }


        /// <summary>
        /// 有效率
        /// </summary>
        public double EffectiveRate => CalcEffectiveRate();

        public double CalcEffectiveRate()
        {
            if (TimelyAnswerCount != 0 && ConnectCount != 0)
            {
                return Math.Round((TimelyAnswerCount / (double)ConnectCount) * 100, 2);
            }
            return 0;
        }
    }
}
