using DotNetCore.CAP;
using Hotline.Application.CallCenter;
using Hotline.Share.Dtos.Order;
using Hotline.Share.Mq;
using XF.Domain.Dependency;

namespace Hotline.Application.OrderApp.Handlers.OrderHandler
{
    public class OrderRelateCallHandler : ICapSubscribe, ITransientDependency
    {
        private readonly ICallApplication _callApplication;

        public OrderRelateCallHandler(ICallApplication callApplication)
        {
            _callApplication = callApplication;
        }

        /// <summary>
        /// 工单关联通话记录
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [CapSubscribe(EventNames.OrderRelateCall)]
        public async Task OrderRelateCallAsync(string orderId, CancellationToken cancellationToken)
        {
            await _callApplication.OrderRelateCallHandlerAsync(orderId, cancellationToken);
        }
    }

    /// <summary>
    /// 保存回访详情时发送延迟消息同步通话记录
    /// 如果回访通话记录有多条, 需要关联通话时长最长的那条
    /// </summary>
    public class OrderVisitRelateCallHandler : ICapSubscribe, ITransientDependency
    {
        private readonly ICallApplication _callApplication;

        public OrderVisitRelateCallHandler(ICallApplication callApplication)
        {
            _callApplication = callApplication;
        }

        [CapSubscribe(EventNames.VisitCallDelay)]
        public async Task OrderVisitRelateCallAsync(VisitDto dto, CancellationToken cancellationToken)
        {
            await _callApplication.OrderVisitRelevanceCallIdAsync(dto, cancellationToken);
        }
    }
}
