using Hotline.CallCenter.Configs;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using NewRock.Sdk;
using NewRock.Sdk.Control.Request;
using NewRock.Sdk.Control.Response;
using NewRock.Sdk.Manage.Request;
using NewRock.Sdk.Manage.Response;
using NewRock.Sdk.Transfer.Conference.Request;
using NewRock.Sdk.Transfer.Connect.Request;
using NewRock.Sdk.Transfer.Queue.Request;
using Ext = NewRock.Sdk.Control.Request.Base.Ext;
using Group = NewRock.Sdk.Control.Request.Group;
using VisitorToExtVisitor = NewRock.Sdk.Transfer.Connect.Request.VisitorToExtVisitor;

namespace Hotline.Api.Controllers
{
    /// <summary>
    /// 设备测试专用，外部禁止调用
    /// </summary>
    [AllowAnonymous]
    public class TestSdkController : BaseController
    {
        private readonly INewRockClient _client;
        private readonly ILogger<TestController> _logger;
        private readonly IOptionsSnapshot<CallCenterConfiguration> _options;

        public TestSdkController(
            INewRockClient client,
            ILogger<TestController> logger,
            IOptionsSnapshot<CallCenterConfiguration> options
            )
        {
            _client = client;
            _logger = logger;
            _options = options;
        }

        #region  查询（Query）

        /// <summary>
        /// 查询设备
        /// </summary>
        /// <returns></returns>
        [HttpGet("QueryDeviceInfo")]
        public async Task QueryDeviceInfo()
        {
            var result = await _client.QueryDeviceInfo(
                new QueryDeviceInfoRequest { Attribute = "Query", DeviceInfo = string.Empty },
                _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
            _logger.LogInformation(System.Text.Json.JsonSerializer.Serialize<QueryDeviceInfoResponse?>(result));
        }


        /// <summary>
        /// 查询分机
        /// </summary>
        /// <returns></returns>
        [HttpPost("QueryExt")]
        public async Task QueryExt(string extid)
        {
            var result = await _client.QueryExt(
                new QueryExtRequest() { Attribute = "Query", Ext = new Ext() { Id = extid } },
                _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted
            );
            _logger.LogInformation(System.Text.Json.JsonSerializer.Serialize<QueryExtResponse?>(result));
        }

        /// <summary>
        /// 查询分机组
        /// </summary>
        /// <param name="groupid"></param>
        /// <returns></returns>
        [HttpPost("QueryExtGroup")]
        public async Task QueryExtGroup(string? groupid)
        {
            var result = await _client.QueryExtGroup(new QueryExtGroupRequest()
            {
                Attribute = "Query",
                Group = new QueryExtGroup() { Id = groupid }
            }, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
            _logger.LogInformation(System.Text.Json.JsonSerializer.Serialize<QueryExtGroupResponse?>(result));
        }

        /// <summary>
        /// 查询语音菜单
        /// </summary>
        /// <param name="menuid"></param>
        /// <returns></returns>
        [HttpPost("QueryMenu")]
        public async Task QueryMenu(string menuid)
        {
            var result = await _client.QueryMenu(new QueryMenuRequest()
            {
                Attribute = "Query",
                Menu = new QueryMenuMenu() { Id = menuid }
            }, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
            _logger.LogInformation(System.Text.Json.JsonSerializer.Serialize<QueryMenuResponse?>(result));
        }

        /// <summary>
        /// 查询中继
        /// </summary>
        /// <param name="trunkid"></param>
        /// <returns></returns>
        [HttpPost("QueryTrunk")]

        public async Task QueryTrunk(string trunkid)
        {
            var result = await _client.QueryTrunk(new QueryTrunkRequest()
            {
                Attribute = "Query",
                Trunk = new QueryTrunkTrunk() { Id = trunkid }
            },
               _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
            _logger.LogInformation(System.Text.Json.JsonSerializer.Serialize<QueryTrunkResponse?>(result));
        }

        /// <summary>
        /// 查询来电
        /// </summary>
        /// <param name="visitorid"></param>
        /// <returns></returns>
        [HttpPost("QueryVisitor")]
        public async Task QueryVisitor(string visitorid)
        {
            var result = await _client.QueryVisitor(new QueryVisitorRequest()
            {
                Attribute = "Query",
                Visitor = new QueryVisitorVisitor() { Id = visitorid }
            }, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
            _logger.LogInformation(System.Text.Json.JsonSerializer.Serialize<QueryVisitorResponse?>(result));
        }

        /// <summary>
        /// 查询去电
        /// </summary>
        /// <param name="outerid"></param>
        /// <returns></returns>
        [HttpPost("QueryOuter")]
        public async Task QueryOuter(string outerid)
        {
            var result = await _client.QueryOuter(new QueryOuterRequest()
            {
                Attribute = "Query",
                Outer = new QueryOuterOuter() { Id = outerid }
            },
               _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
            _logger.LogInformation(System.Text.Json.JsonSerializer.Serialize<QueryOuterResponse?>(result));
        }

        #endregion

        #region 强拆

        /// <summary>
        /// 强拆分机
        /// </summary>
        /// <param name="extid"></param>
        /// <returns></returns>
        [HttpPost("ClearExt")]
        public async Task ClearExt(string extid)
        {
            var result = await _client.ClearCall(new ClearCallRequest()
            {
                Attribute = "Clear",
                Ext = new Ext()
                {
                    Id = extid
                },
            }, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
        }

        /// <summary>
        /// 强拆来电
        /// </summary>
        /// <param name="visitorId"></param>
        /// <returns></returns>
        [HttpPost("ClearVisitor")]
        public async Task ClearVisitor(string visitorId)
        {
            var result = await _client.ClearCall(new ClearCallRequest()
            {
                Attribute = "Clear",
                Visitor = new ClearCallVisitor()
                {
                    Id = visitorId
                }
            }, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
        }

        /// <summary>
        /// 强拆去电
        /// </summary>
        /// <param name="outerId"></param>
        /// <returns></returns>
        [HttpPost("ClearOuter")]
        public async Task ClearOuter(string outerId)
        {
            var result = await _client.ClearCall(new ClearCallRequest()
            {
                Attribute = "Clear",
                Outer = new ClearCallOuter()
                {
                    Id = outerId
                }
            }, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
        }

        #endregion

        #region 配置（Assign）

        /// <summary>
        /// 配置分机
        /// </summary>
        /// <returns></returns>
        [HttpGet("ConfigExt")]
        public async Task ConfigExt()
        {
            var result = await _client.ConfigExt(new AssginConfigExtRequest()
            {
                Attribute = "Assign",
                Ext = new ConfigExt()
                {
                    Lineid = "IPPhone 21",
                    Id = "212",
                    //Staffid = "038",
                    Groups = new List<string>()
                    {
                        "1",
                        "2",
                    },
                    //VoiceFile = "user_tts164815.dat",
                    //Call_Restriction = "2",
                    //Call_Pickup ="no",
                    No_Disturb = "on",
                    Fwd_Type = "0",
                    //Record="on",
                    Api = "7"
                }
            },
           _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
            HttpContext.RequestAborted);
            _logger.LogInformation(System.Text.Json.JsonSerializer.Serialize<AssginConfigExtResponse?>(result));
        }


        /// <summary>
        /// 配置分机组
        /// </summary>
        /// <returns></returns>
        [HttpGet("ConfigExtGroup")]
        public async Task ConfigExtGroup()
        {
            var result = await _client.ConfigExtGroup(new AssginConfigGroupRequest()
            {
                Attribute = "Assign",
                Group = new Group()
                {
                    Id = "1",
                    Voicefile = "NewMorning",
                    Distribution = "sequential",
                    Ext = new List<string>()
                    {
                        "209",
                        "210"
                    }
                }
            }, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
            HttpContext.RequestAborted);
            _logger.LogInformation(System.Text.Json.JsonSerializer.Serialize<AssginConfigGroupResponse?>(result));
        }

        /// <summary>
        /// 配置语音菜单
        /// </summary>
        /// <returns></returns>
        [HttpGet("ConfigMenu")]
        public async Task ConfigMenu()
        {
            var result = await _client.ConfigMenu(new AssginConfigMenuRequest()
            {
                Attribute = "Assign",
                Menu = new AssginConfigMenuMenu()
                {
                    Id = "1",
                    VoiceFile = "user_tts131742",
                    Exit = "#",
                    Repeat = "3",
                    InfoLength = "5",
                }
            }, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
        }

        #endregion

        #region 呼叫保持和接回

        /// <summary>
        /// 呼叫保持
        /// </summary>
        /// <returns></returns>
        [HttpPost("Hold")]
        public async Task Hold(string extid)
        {
            var result = await _client.HoldOrUnHold(new HoldSetRequest()
            {
                Attribute = "Hold",
                Ext = new Ext() { Id = extid }
            }, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
            //_logger.LogInformation(result.Manufacturer);
        }

        /// <summary>
        /// 呼叫接回
        /// </summary>
        /// <returns></returns>
        [HttpPost("UnHold")]
        public async Task UnHold(string extid)
        {
            var result = await _client.HoldOrUnHold(new HoldSetRequest()
            {
                Attribute = "Unhold",
                Ext = new Ext() { Id = extid }
            }, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
        }

        #endregion

        #region 静音开启与解除

        /// <summary>
        /// 静音
        /// </summary>
        /// <param name="extid"></param>
        /// <returns></returns>
        [HttpPost("Mute")]
        public async Task Mute(string extid)
        {
            var result = await _client.MuteOrUnMute(new MuteSetRequest
            {
                Attribute = "Mute",
                Ext = new Ext() { Id = extid }
            }, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
        }

        /// <summary>
        /// 解除静音
        /// </summary>
        /// <param name="extid"></param>
        /// <returns></returns>
        [HttpPost("UnMute")]
        public async Task UnMute(string extid)
        {
            var result = await _client.MuteOrUnMute(new MuteSetRequest
            {
                Attribute = "Unmute",
                Ext = new Ext() { Id = extid }
            }, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
        }

        #endregion

        #region 呼叫转接命令（Transfer）

        #region 连接（Connect）

        /// <summary>
        /// 分机呼分机
        /// </summary>
        /// <returns></returns>
        [HttpPost("ExtensionToExtension")]
        public async Task ExtensionToExtension(string fromextid, string toextid)
        {
            var result = await _client.ExtensionToExtension(new ExtensionToExtensionRequest()
            {
                Attribute = "Connect",
                Exts = new List<ExtToExtExt>()
                    {
                        new ExtToExtExt() { Id = fromextid },
                        new ExtToExtExt() { Id = toextid }
                    }
            }, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
            _logger.LogInformation(System.Text.Json.JsonSerializer.Serialize(result));
        }

        /// <summary>
        /// 分机呼外部电话
        /// </summary>
        /// <returns></returns>
        [HttpPost("ExtToOuter")]
        public async Task ExtToOuter(string fromextid, string to)
        {
            var result = await _client.ExtToOuter(new ExtToOuterRequest()
            {
                Attribute = "Connect",
                Ext = new ExtToOuterExtRequest() { Id = fromextid },
                Outer = new ExtToOuterOuterRequest() { To = to }
            },
               _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
        }

        /// <summary>
        /// 来电转分机
        /// </summary>
        /// <returns></returns>
        [HttpPost("VisitorToExt")]
        public async Task VisitorToExt(string visid, string toextid)
        {
            var result = await _client.VisitorToExt(new VisitorToExtRequest()
            {
                Attribute = "Connect",
                Visitor = new VisitorToExtVisitor() { Id = visid },
                Ext = new VisitorToExtExt() { Id = toextid }
            }, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
        }

        /// <summary>
        /// 来电转外部电话
        /// </summary>
        /// <param name="visid"></param>
        /// <param name="outerphonenum"></param>
        /// <param name="display"></param>
        /// <returns></returns>
        [HttpPost("VisitorToOuter")]
        public async Task VisitorToOuter(string visid, string outerphonenum, string display = "")
        {
            var result = await _client.VisitorToOuter(new VisitorToOuterRequest()
            {
                Attribute = "Connect",
                Visitor = new VisitorToOuterVisitor() { Id = visid },
                Outer = new VisitorToOuterOuter() { To = outerphonenum, Display = display },

            }, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
        }

        /// <summary>
        /// 来电转语音菜单
        /// </summary>
        /// <param name="visid"></param>
        /// <param name="menuid"></param>
        /// <returns></returns>
        [HttpPost("VisitorToMenu")]
        public async Task VisitorToMenu(string visid, string menuid)
        {
            var result = await _client.VisitorToMenu(new VisitorToMenuRequest()
            {
                Attribute = "Connect",
                Visitor = new VisitorToMenuVisitor() { Id = visid },
                Menu = new VisitorToMenuMenu() { Id = menuid }
            }, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
        }

        /// <summary>
        /// 去电转分机
        /// </summary>
        /// <param name="outer"></param>
        /// <param name="extid"></param>
        /// <returns></returns>
        [HttpPost("OuterToExt")]
        public async Task OuterToExt(string outer, string extid)
        {
            var result = await _client.OuterToExt(new OuterToExtRequest()
            {
                Attribute = "Connect",
                Outer = new OuterToExtOuter() { Id = outer },
                Ext = new OuterToExtExt() { Id = extid }
            },
               _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
        }


        /// <summary>
        /// 去电转外部电话
        /// </summary>
        /// <param name="outerid"></param>
        /// <param name="outerphonenum"></param>
        /// <returns></returns>
        [HttpPost("OuterToOuter")]
        public async Task OuterToOuter(string outerid, string outerphonenum)
        {
            var result = await _client.OuterToOuter(new OuterToOuterRequest()
            {
                Attribute = "Connect",
                Outer = new List<OuterToOuterOuterModel>() { new OuterToOuterOuterModel() { Id = outerid }, new OuterToOuterOuterModel() { To = outerphonenum } },
            }, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
        }

        /// <summary>
        /// 去电转语音菜单
        /// </summary>
        /// <param name="outerid"></param>
        /// <param name="menuid"></param>
        /// <returns></returns>
        [HttpPost("OuterToMenu")]
        public async Task OuterToMenu(string outerid, string menuid)
        {
            var result = await _client.OuterToMenu(new OuterToMenuRequest()
            {
                Attribute = "Connect",
                Outer = new OuterToMenuOuter() { Id = outerid },
                Menu = new OuterToMenuMenu() { Id = menuid }
            }, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
        }

        /// <summary>
        /// 语音菜单呼分机
        /// </summary>
        /// <param name="menuid"></param>
        /// <param name="extid"></param>
        /// <returns></returns>
        [HttpPost("MenuToExt")]
        public async Task MenuToExt(string menuid, string extid)
        {
            var result = await _client.MenuToExt(new MenuToExtRequest()
            {
                Attribute = "Connect",
                Menu = new MenuToExtMenu() { Id = menuid },
                Ext = new MenuToExtExt() { Id = extid }
            }, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
        }

        /// <summary>
        /// 语音菜单呼外部电话
        /// </summary>
        /// <param name="menuid"></param>
        /// <param name="outernum"></param>
        /// <returns></returns>
        [HttpPost("MenuToOuter")]
        public async Task MenuToOuter(string menuid, string outernum)
        {
            var result = await _client.MenuToOuter(new MenuToOuterRequest()
            {
                Attribute = "Connect",
                Menu = new MenuToOuterMenu() { Id = menuid },
                Outer = new MenuToOuterOuter() { To = outernum }
            }, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
        }


        /// <summary>
        /// 双向呼叫（回拨）
        /// </summary>
        /// <param name="outerone"></param>
        /// <param name="outertwo"></param>
        /// <returns></returns>
        [HttpPost("TwoWayOuter")]
        public async Task TwoWayOuter(string outerone, string outertwo)
        {
            var result = await _client.TwoWayOuter(new TwoWayOuterRequest()
            {
                Attribute = "Connect",
                Outer = new List<TwoWayOuterOuter>()
                    {
                        new TwoWayOuterOuter(){ To = outerone},
                        new TwoWayOuterOuter(){ To = outertwo}
                    }
            }, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
        }

        /// <summary>
        /// 语音插播（分机）
        /// </summary>
        /// <param name="extid"></param>
        /// <param name="voicefile"></param>
        /// <returns></returns>
        [HttpPost("VoiceNewsFlash")]
        public async Task VoiceNewsFlashExt(string voicefile, string extid)
        {
            var model = new VoiceNewsFlashRequest
            {
                Attribute = "Connect",
                VoiceFile = voicefile,
                Ext = new VoiceNewsFlashExt() { Id = extid }
            };

            var result = await _client.VoiceNewsFlash(model, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
        }

        /// <summary>
        /// 语音插播（来电）
        /// </summary>
        /// <param name="voicefile"></param>
        /// <param name="visiitorid"></param>
        /// <returns></returns>
        [HttpPost("VoiceNewsFlashVisitor")]
        public async Task VoiceNewsFlashVisitor(string voicefile, string visiitorid)
        {
            var model = new VoiceNewsFlashRequest
            {
                Attribute = "Connect",
                VoiceFile = voicefile,
                Visitor = new VoiceNewsFlashVisitor() { Id = visiitorid }
            };

            var result = await _client.VoiceNewsFlash(model, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
        }

        /// <summary>
        /// 语音插播（去电）
        /// </summary>
        /// <param name="voicefile"></param>
        /// <param name="outerid"></param>
        /// <returns></returns>
        [HttpPost("VoiceNewsFlashOuter")]
        public async Task VoiceNewsFlashOuter(string voicefile, string outerid)
        {
            var model = new VoiceNewsFlashRequest
            {
                Attribute = "Connect",
                VoiceFile = voicefile,
                Outer = new VoiceNewsFlashOuter() { Id = outerid }
            };

            var result = await _client.VoiceNewsFlash(model, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
        }


        #endregion


        #region 会议（Conference）

        /// <summary>
        /// 会议
        /// </summary>
        /// <param name="extid"></param>
        /// <returns></returns>
        [HttpPost("ConferenceMeeting")]
        public async Task ConferenceMeeting(string extid)
        {
            var result = await _client.ConferenceMeeting(new ConferenceMeetingRequest()
            {
                Attribute = "Conference",
                Ext = new ConferenceMeetingExt() { Id = extid }
            }, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
        }

        #endregion


        #region 队列（Queue）

        /// <summary>
        /// 来电转分机队列
        /// </summary>
        /// <param name="visitorid"></param>
        /// <param name="extid"></param>
        /// <returns></returns>
        [HttpPost("VisitorToExtQueue")]
        public async Task VisitorToExtQueue(string visitorid, string extid)
        {
            var result = await _client.VisitorToExtQueue(new VisitorToExtQueueRequest()
            {
                Attribute = "Queue",
                Visitor = new VisitorToExtQueueVisitor() { Id = visitorid },
                Ext = new VisitorToExtQueueExt() { Id = extid }
            }, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
        }

        /// <summary>
        ///来电转分机组队列
        /// </summary>
        /// <param name="visitorid"></param>
        /// <param name="groupid"></param>
        /// <returns></returns>
        [HttpPost("VisitorToGroupQueue")]
        public async Task VisitorToGroupQueue(string visitorid, string groupid)
        {
            var result = await _client.VisitorToGroupQueue(new VisitorToGroupQueueRequest()
            {
                Attribute = "Queue",
                Visitor = new VisitorToGroupQueueVisitor() { Id = visitorid },
                Group = new VisitorToGroupQueueGroup() { Id = groupid }
            },
               _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
        }

        #endregion


        #endregion

        #region 语音管理命令

        /// <summary>
        /// 查询语音文件
        /// </summary>
        /// <returns></returns>
        [HttpGet("VoiceQueryList")]
        public async Task VoiceQueryList()
        {
            var result = await _client.VoiceQueryList(new VoiceQueryListRequest()
            {
                Attribute = "Query",
                VoiceFile = ""
            }, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
            _logger.LogInformation(System.Text.Json.JsonSerializer.Serialize<VoiceQueryListResponse?>(result));
        }

        /// <summary>
        /// 删除语音文件
        /// </summary>
        /// <param name="voiceFile"></param>
        /// <returns></returns>
        [HttpPost("RemoveVoiceFile")]
        public async Task RemoveVoiceFile(string voiceFile)
        {
            await _client.RemoveVoiceFile(new RemoveVoiceFileRequest()
            {
                Attribute = "Remove",
                VoiceFile = voiceFile
            }, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
                HttpContext.RequestAborted);
        }

        #endregion

        #region 监听和强插

        /// <summary>
        /// 监听分机
        /// </summary>
        /// <param name="firstTelNo"></param>
        /// <param name="secondTelNo"></param>
        /// <returns></returns>
        [HttpPost("MonitorExt")]
        public async Task MonitorExt(string firstTelNo,string secondTelNo)
        {
            await _client.MonitorExt(new MonitorExtRequest()
            {
                Attribute = "Monitor",
                Exts = new List<Ext>() { new Ext() { Id = firstTelNo }, new Ext() { Id = secondTelNo } }
            }, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
             HttpContext.RequestAborted) ;
        }

        /// <summary>
        /// 从监听到插播状态变换
        /// 1. 已知：分机 A 在监听分机 B 与其通话方的通话；
        /// 2. 执行分机 A 的从监听到插播状态变换的 API；
        /// 3. 执行成功时，分机 A 与分机 B 建立通话，分机 B 的原通话方听保持音。
        /// </summary>
        /// <param name="telNo"></param>
        /// <returns></returns>
        [HttpPost("MonitorExtToTalk")]
        public async Task MonitorExtToTalk(string telNo)
        {
            await _client.MonitorExtToTalk(new MonitorExtToTalkRequest()
            {
                Attribute = "Talk",
                Ext = new Ext() { Id=telNo }
            }, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
              HttpContext.RequestAborted);
        }

        /// <summary>
        /// 从插播到监听状态变换
        /// 1. 已知：分机 A 在插播分机 B 的通话；
        /// 2. 执行分机 A 的从插播到监听状态变换的 API；
        /// 3. 执行成功时，分机 A 监听分机 B 及其原通话方的通话。
        /// </summary>
        /// <param name="telNo"></param>
        /// <returns></returns>
        [HttpPost("MonitorExtToListen")]
        public async Task MonitorExtToListen(string telNo)
        {
            await _client.MonitorExtToListen(new MonitorExtToListenRequest()
            {
                Attribute = "Listen",
                Ext = new Ext() { Id = telNo }
            }, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
             HttpContext.RequestAborted);
        }


        #endregion


        #region 强插

        /// <summary>
        /// 强插
        /// 1. 已知：分机 A 当前空闲，分机 B 正在通话中；
        /// 2. 执行分机 A 强插分机 B 的 API；
        /// 3. 执行成功时，分机 A 振铃，摘机后即可形成三方通话。
        /// </summary>
        /// <param name="firstTelNo"></param>
        /// <param name="secondTelNo"></param>
        /// <returns></returns>
        [HttpPost("BargeinExt")]
        public async Task BargeinExt(string firstTelNo,string secondTelNo)
        {
            await _client.BargeinExt(new BargeinExtRequest()
            {
                Attribute = "BargeinExt",
                Exts = new List<Ext>() { new Ext() { Id=firstTelNo },new Ext() { Id=secondTelNo } }
            }, _options.Value.NewRock.ReceiveKey,
                _options.Value.NewRock.Expired,
             HttpContext.RequestAborted);
        }


        #endregion


    }
}
