using Hotline.CallCenter.Tels;
using Hotline.Share.Dtos.CallCenter;
using Hotline.Share.Notifications.NewRockCallCenter;
using Mapster;
using NewRock.Sdk.Control.Response;
using NewRock.Sdk.Events;

namespace Hotline.NewRock.Mappers
{
    public class EventConfigs : IRegister
    {
        public void Register(TypeAdapterConfig config)
        {
            #region 上线事件
            //上线事件
            config.NewConfig<OnlineEvent, OnlineNotification>()
                .Map(d => d.TelNo, x => x.Ext.Id);
            #endregion

            #region 离线事件

            //下线事件
            config.NewConfig<OfflineEvent, OfflineNotification>()
                .Map(d => d.TelNo, x => x.Ext.Id);

            #endregion

            #region 空闲事件

            config.NewConfig<IdleEvent, IdleNotification>()
                .Map(d => d.TelNo, x => x.Ext.Id);

            #endregion

            #region 忙事件

            config.NewConfig<BusyEvent, BusyNotification>()
                .Map(d => d.TelNo, x => x.Ext.Id);

            #endregion


            #region 振铃时间
            //分机呼分机
            config.NewConfig<RingEvent, RingExtToExtNotification>()
                .Map(d => d.FromTelNo, x => x.Ext.First().Id)
                .Map(d => d.ToTelNo, x => x.Ext.Last().Id);
            //来电转分机
            config.NewConfig<RingEvent, RingVisitorToExtNotification>()
                .Map(d => d.TelNo, x => x.Ext.First().Id);
            //分机外呼/分机呼分机
            config.NewConfig<RingEvent, RingExtToOuterNotification>()
                .Map(d => d.TelNo, x => x.Ext.First().Id);
            //menu呼叫分机
            config.NewConfig<RingEvent, RingMenuToExtNotification>()
                .Map(d => d.TelNo, x => x.Ext.First().Id)
                .Map(d => d.MenuId, x => x.Menu.Id);

            #endregion

            #region 回铃事件
            //来电转分机，分机回铃
            config.NewConfig<AlertEvent, AlertVisitorToExtNotification>()
                .Map(d => d.TelNo, x => x.Ext.First().Id);

            //分机呼外部电话，外部电话回铃
            config.NewConfig<AlertEvent, AlertExtToOuterNotification>()
                .Map(d => d.TelNo, x => x.Ext.First().Id);

            //分机呼分机，被叫分机回铃
            config.NewConfig<AlertEvent, AlertExtToExtNotification>()
                .Map(d => d.FromTelNo, x => x.Ext.First().Id)
                .Map(d => d.ToTelNo, x => x.Ext.Last().Id);
            #endregion

            #region 呼叫应答事件

            //分机呼分机，被叫分机应答
            config.NewConfig<AnswerEvent, AnswerExtToExtNotification>()
                .Map(d => d.FromTelNo, x => x.Ext.First().Id)
                .Map(d=>d.ToTelNo,x=>x.Ext.Last().Id);
            //来电转分机，分机应答
            config.NewConfig<AnswerEvent, AnswerViisitorToExtNotification>()
                .Map(d => d.TelNo, x => x.Ext.First().Id);

            #endregion

            #region 呼叫被应答事件
            //分机呼分机，主叫分机检查到被叫分机应答
            config.NewConfig<AnsweredEvent,AnsweredExtToExtNotification>()
                .Map(d => d.FromTelNo, x => x.Ext.First().Id)
                .Map(d => d.ToTelNo, x => x.Ext.Last().Id);
            //分机呼外部电话，分机检查到外部电话应答
            config.NewConfig<AnsweredEvent, AnsweredExtToOuterNotification>()
                .Map(d => d.TelNo, x => x.Ext.First().Id);
            //来电呼分机，分机应答
            config.NewConfig<AnsweredEvent, AnsweredVisitorToExtNotification>()
                .Map(d => d.TelNo, x => x.Ext.First().Id);
            #endregion

            #region 通话结束事件
            //来电和分机的通话结束，来电挂断
            config.NewConfig<ByeEvent, ByeVisitorAndExtNotification>()
                .Map(d => d.TelNo, x => x.Ext[0].Id);
            //分机和去电的通话结束，分机挂断 类型一
            config.NewConfig<ByeEvent, ByeExtAndOuterOneNotification>()
                .Map(d => d.TelNo, x => x.Ext[0].Id);
            //分机和分机的通话结束
            config.NewConfig<ByeEvent, ByeExtAndExtNotification>()
                .Map(d => d.FromTelNo, x => x.Ext[0].Id)
                .Map(d => d.ToTelNo, x => x.Ext[1].Id);
            #endregion

            #region 呼叫转移事件

            config.NewConfig<DivertEvent, DivertExtToExtNotification>()
                .Map(d => d.TelNo, x => x.Ext.Id);

            #endregion

            #region 呼叫临时事件

            config.NewConfig<TransientEvent, TransientOuterNotification>()
                .Map(d => d.TelNo, x => x.Ext.Id);

            #endregion

            #region 呼叫失败事件

            config.NewConfig<FailedEvent, FailedNotification>()
                .Map(d => d.CalledId, x => x.Called.Id)
                .Map(d => d.Code, x => x.Err.Code)
                .Map(d => d.Reason, x => x.Err.Reason);

            #endregion

            #region 来电呼叫请求事件

            config.NewConfig<InviteEvent, InviteNotification>()
                .Map(d => d.TrunkId, x => x.Trunk.Id);

            #endregion

            #region 来电呼入事件

            config.NewConfig<IncomingEvent, IncomingNotification>()
                .Map(d => d.TrunkId, x => x.Trunk.Id);

            #endregion

            #region 按键信息事件

            config.NewConfig<DtmfEvent, DtmfNotification>()
                .Map(d => d.Outer.MenuId, x => x.Outer.Menu.Id)
                .Map(d => d.Outer.TrunkId, x => x.Outer.Trunk.Id)
                .Map(d => d.Visitor.MenuId, x => x.Visitor.Menu.Id)
                .Map(d => d.Visitor.TrunkId, x => x.Visitor.Trunk.Id);

            #endregion


            #region 语音文件播放完毕

            config.NewConfig<EndOfAnnEvent, EndOfAnnVisitorToMenuNotification>()
                .Map(d => d.MenuId, x => x.Menu.Id);
            config.NewConfig<EndOfAnnEvent, EndOfAnnOuterToMenuNotification>()
                .Map(d => d.MenuId, x => x.Menu.Id);
            config.NewConfig<EndOfAnnEvent, EndOfAnnExtToMenuNotification>()
                .Map(d => d.MenuId, x => x.Menu.Id)
                .Map(d => d.TelNo, x => x.Ext.Id);

            #endregion

            #region 分机组队列事件

            config.NewConfig<QueueEvent, QueueExtToGroupBusyNotification>()
                .Map(d => d.TelNo, x => x.Ext.Id);
            config.NewConfig<QueueEvent, QueueExtToGroupOfflineNotification>()
                .Map(d => d.TelNo, x => x.Ext.Id);
            config.NewConfig<QueueEvent, QueueExtToGroupFullNotification>()
                .Map(d => d.TelNo, x => x.Ext.Id);


            #endregion

            #region 接口调用

            //查询全部分机
            config.NewConfig<DevicesExt, Tel>()
                .Map(d => d.No, x => x.Id)
                .Ignore(d=>d.Id);
            //查询全部分机组
            config.NewConfig<DevicesGroupExt, Tel>()
                .Map(d => d.No, x => x.Id)
                .Ignore(d => d.Id);
            config.NewConfig<DevicesGroup, TelGroup>()
                .Map(d => d.No, x => x.Id)
                .Map(d => d.Tels, x => x.Ext)
                .Ignore(d => d.Id);
            //查询分机
            config.NewConfig<QueryExtResponse, TelDto>()
                .Map(d => d.CPN, x => x.Ext.Visitor.From)
                .Map(d => d.CPN, x => x.Ext.Outer.From)
                .Map(d => d.CDPN, x => x.Ext.Visitor.To)
                .Map(d => d.CDPN, x => x.Ext.Visitor.To);
            #endregion

        }
    }
}
