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

namespace Hotline.Share.Dtos.CallCenter
{
    public class CenterReportStatisticsDto
    {
        /// <summary>
        /// 电话
        /// </summary>
        public CenterReportCallInfoDto CenterReportCallInfoDto { get; set; }

        /// <summary>
        /// 电话
        /// </summary>
        public CenterReportCallDto CenterReportCall { get; set; }

        /// <summary>
        /// 工单
        /// </summary>
        public CenterReportOrderDto CenterReportOrder { get; set; }

        /// <summary>
        /// 信件回访量
        /// </summary>
        public CenterReportVisitdDto CenterReportVisitd { get; set; }

        /// <summary>
        /// 来源
        /// </summary>
        public List<CenterReportOrderSourceChannelDto> CenterReportOrderSourceChannels { get; set; }

        /// <summary>
        /// 信件分类
        /// </summary>
        public List<CenterReportOrderSourceChannelDto> CenterReportOrderAcceptTypes { get; set; }

        /// <summary>
        /// 专线统计
        /// </summary>
        public List<CenterReportOrderSourceChannelDto>  CenterReportOrderDedicatedLine{get;set ;}

        /// <summary>
        /// 市直部门
        /// </summary>
        public OrgStatisticsAll OrgStatisticsCityAll { get; set; }

        /// <summary>
        /// 区县部门
        /// </summary>
        public OrgStatisticsAll OrgStatisticsAreaAll { get; set; }
    }

    /// <summary>
    /// 话务情况
    /// </summary>
    public class CenterReportCallInfoDto
    {
        /// <summary>
        /// 话务总量
        /// </summary>
        public int AllCallCount { get; set; }

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

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

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

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

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

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

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

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

        /// <summary>
        /// 呼入未接通
        /// </summary>
        public int CallInHanguped => InHanguped - QueueByeCount - IvrByeCount;
    }

    /// <summary>
    /// 话务量
    /// </summary>
    public class CenterReportCallDto
    {
        /// <summary>
        /// 话务总量
        /// </summary>
        public int AllCallCount => EffectiveCount + InvalidCount + QueueByeCount + IvrByeCount;

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

        /// <summary>
        /// 无效
        /// </summary>
        public int InvalidCount { get; set; }

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

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

    /// <summary>
    /// 工单数据
    /// </summary>
    public class CenterReportOrderDto
    {
        /// <summary>
        /// 工单总量
        /// </summary>
        public int AllCallCount => EffectiveCount + InvalidCount;

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

        /// <summary>
        /// 无效
        /// </summary>
        public int InvalidCount { get; set; }

        /// <summary>
        /// 已办结
        /// </summary>
        public int CompletedCount { get; set; }

        /// <summary>
        /// 按时办结
        /// </summary>
        public int OnTimeCompletedCount { get; set; }

        /// <summary>
        /// 按时办结率
        /// </summary>
        public double OnTimeCompletedCountClc => CalcRate();

        /// <summary>
        /// 计算办结率
        /// </summary>
        /// <returns></returns>
        public double CalcRate()
        {
            if (OnTimeCompletedCount > 0 && CompletedCount > 0)
                return Math.Round(((double)OnTimeCompletedCount / CompletedCount) * 100, 2);
            return 0;
        }

        /// <summary>
        /// 中心已办结
        /// </summary>
        public int CenterCompletedCount { get; set; }

        /// <summary>
        /// 部门已办结
        /// </summary>
        public int OrgCompletedCount { get; set; }

        /// <summary>
        /// 在办
        /// </summary>
        public int InProgressCount { get; set; }

        /// <summary>
        /// 中心在办
        /// </summary>
        public int CenterInProgressCount { get; set; }

        /// <summary>
        /// 部门在办
        /// </summary>
        public int OrgInProgressCount { get; set; }


    }

    /// <summary>
    /// 信件来源
    /// </summary>
    public class CenterReportOrderSourceChannelDto
    {
        /// <summary>
        /// 名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 编码
        /// </summary>
        public string Code { get; set; }

        /// <summary>
        /// 总量
        /// </summary>
        public int AllCountNum { get; set; }

        /// <summary>
        /// 数量
        /// </summary>
        public int CountNum { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string Remark { get; set; }

        /// <summary>
        /// 占比
        /// </summary>
        public double ProportionRate => CalcProportionRate();

        public double CalcProportionRate()
        {
            if (AllCountNum != 0 && CountNum != 0)
            {
                return Math.Round((CountNum / (double)AllCountNum) * 100, 2);
            }
            return 0;
        }
    }

    /// <summary>
    /// 信件回访量
    /// </summary>
    public class CenterReportVisitdDto
    {
        /// <summary>
        /// 已回访
        /// </summary>
        public int Visitd { get; set; }

        /// <summary>
        /// 已回访--电话
        /// </summary>
        public int CallVisitd { get; set; }

        /// <summary>
        /// 已回访--短信
        /// </summary>
        public int SmsVisitd { get; set; }

        /// <summary>
        /// 其他回访
        /// </summary>
        public int OtherVisitd { get; set; }

        /// <summary>
        /// 待回访
        /// </summary>
        public int WaitVisitd { get; set; }

        /// <summary>
        /// 坐席满意度
        /// </summary>
        public double SeatsRate { get; set; }

        /// <summary>
        /// 部门满意度
        /// </summary>
        public double OrgRate { get; set; }
    }

    public class Satisfaction
    {
        /// <summary>
        /// 满意
        /// </summary>
        public int Satisfied { get; set; }

        /// <summary>
        /// 不满意
        /// </summary>
        public int Dissatisfied { get; set; }
    }

    /// <summary>
    /// 信件分布
    /// </summary>
    public class OrgStatisticsAll
    {
        /// <summary>
        /// 总数
        /// </summary>
        public int OrgStatisticsCountAll => Totalize();

        /// <summary>
        /// 明细
        /// </summary>
        public List<OrgStatistics> OrgStatistics { get; set; }

        public int Totalize()
        {
            int SunNum = 0;
            foreach (var item in OrgStatistics)
            {
                SunNum += item.CountNum;
            }

            return SunNum;
        }
    }

    public class OrgStatistics
    {
        /// <summary>
        /// 部门编码
        /// </summary>
        public string OrgCode { get; set; }

        /// <summary>
        /// 部门名称
        /// </summary>
        public string OrgName { get; set; }

        /// <summary>
        /// 工单数量
        /// </summary>
        public int CountNum { get; set; }

        /// <summary>
        /// 办件次数
        /// </summary>
        public int HandleCountNum => CountNum;
    }
}
