using DotNetCore.CAP;
using Hotline.FlowEngine.Notifications;
using Hotline.FlowEngine.WorkflowModules;
using Hotline.Orders;
using Hotline.Share.Dtos.Order;
using Hotline.Share.Enums.FlowEngine;
using Hotline.Share.Enums.Order;
using Hotline.Share.Mq;
using MapsterMapper;
using MediatR;
using Microsoft.Extensions.Logging;

namespace Hotline.Application.Handlers.FlowEngine;

public class JumpHandler : INotificationHandler<JumpNotify>
{
    private readonly IOrderDomainService _orderDomainService;
    private readonly IOrderRepository _orderRepository;
    private readonly ICapPublisher _capPublisher;
    private readonly IMapper _mapper;
    private readonly ILogger<JumpHandler> _logger;

    public JumpHandler(
        IOrderDomainService orderDomainService,
        IOrderRepository orderRepository,
        ICapPublisher capPublisher,
        IMapper mapper,
        ILogger<JumpHandler> logger)
    {
        _orderDomainService = orderDomainService;
        _orderRepository = orderRepository;
        _capPublisher = capPublisher;
        _mapper = mapper;
        _logger = logger;
    }

    /// <summary>Handles a notification</summary>
    /// <param name="notification">The notification</param>
    /// <param name="cancellationToken">Cancellation token</param>
    public async Task Handle(JumpNotify notification, CancellationToken cancellationToken)
    {
        var workflow = notification.Workflow;
        var data = notification.Dto;

        //switch (workflow.ModuleCode)
        //{
        //    case WorkflowModuleConsts.OrderHandle:
        //        var order = await _orderDomainService.GetOrderAsync(workflow.ExternalId, cancellationToken);
        //        _mapper.Map(workflow, order);
        //        if (notification.TargetStep.StepType is EStepType.Start)
        //            order.Status = EOrderStatus.BackToUnAccept;
        //        await _orderRepository.UpdateAsync(order, cancellationToken);

        //        if (notification.IsOrgToCenter || notification.IsCenterToOrg)
        //        {
        //            var dto = _mapper.Map<OrderDto>(order);
        //            await _capPublisher.PublishAsync(EventNames.HotlineOrderExpiredTimeUpdate, dto, cancellationToken: cancellationToken);
        //        }

        //        break;
        //}
    }
}