using Hotline.Application.OrderApp;
using Hotline.Caching.Interfaces;
using Hotline.Early;
using Hotline.Orders;
using Hotline.Push.FWMessage;
using Hotline.Push.Notifies;
using Hotline.Settings;
using Hotline.Share.Dtos.Order;
using Hotline.Share.Dtos.Settings;
using Hotline.Share.Enums.Order;
using Mapster;
using NPOI.SS.Formula.Functions;
using Shouldly;
using XF.Domain.Repository;

namespace Hotline.Tests.Application;
public class OrderApplicationTest
{
    private readonly IOrderApplication _orderApplication;
    private readonly ISystemDicDataCacheManager _systemDicDataCacheManager;
    private readonly IRepository<OrderVisit> _orderVisitRepository;
    private readonly IRepository<Order> _orderRepository;
    private readonly IRepository<Message> _messageRepository;


    public OrderApplicationTest(IOrderApplication orderApplication, IRepository<OrderVisit> orderVisitRepository, IRepository<Message> messageRepository, IRepository<Order> orderRepository, ISystemDicDataCacheManager systemDicDataCacheManager)
    {
        _orderApplication = orderApplication;
        _orderVisitRepository = orderVisitRepository;
        _orderRepository = orderRepository;
        _systemDicDataCacheManager = systemDicDataCacheManager;
        _messageRepository = messageRepository;
    }

    //[Fact]
    public async Task VisitPushSMS_Test()
    {
        var orderVisit = await _orderVisitRepository.Queryable()
            .Where(m => m.VisitState == EVisitState.WaitForVisit)
            .OrderByDescending(m => m.CreationTime)
            .FirstAsync();
        orderVisit.ShouldNotBeNull("缺少 回访单 (order_visit) VisitState = 10 的数据.");
        var dto = new VisitSmsInDto
        {
            Ids = new List<string> { orderVisit.Id }
        };
        await _orderApplication.VisitPushSMSAsync(dto, new CancellationToken());
        var visit = await _orderVisitRepository.Queryable().Where(m => m.Id == orderVisit.Id).FirstAsync();
        visit.VisitState.ShouldBe(EVisitState.SMSVisiting);
        visit.VisitType.ShouldBe(EVisitType.SmsVisit);
    }


    [Fact]
    public async Task MapConfig_Test()
    {
        var data = await _messageRepository.Queryable().OrderByDescending(m => m.CreationTime)
            .FirstAsync();
        var m = data.Adapt<ReceiveMessageNotify>();
        m.NotifyDto.Name.ShouldBe(data.Name);
        m.NotifyDto.PushBusiness.ShouldBe(data.PushBusiness);

        var a = new SystemDicData { Id = "123"};
        var b = a.Adapt<SystemDicDataOutDto>();
        b.ShouldNotBeNull();
    }
}
