using Hotline.Orders;
using Hotline.Settings;
using Hotline.Settings.TimeLimitDomain;
using Hotline.Share.Dtos.Settings;
using Hotline.Share.Enums.FlowEngine;
using Hotline.Share.Enums.Settings;
using Shouldly;
using XF.Domain.Repository;

namespace Hotline.Tests.Domain;
public class YiBinExpireTimeTest
{
    private readonly YiBinExpireTimeLimit _calcExpireTime;
    private readonly IRepository<Order> _orderRepository;
    private readonly IRepository<TimeLimitSetting> _timeLimitSettingRepository;

    public YiBinExpireTimeTest(YiBinExpireTimeLimit calcExpireTime, IRepository<Order> orderRepository, IRepository<TimeLimitSetting> timeLimitSettingRepository)
    {
        _calcExpireTime = calcExpireTime;
        _orderRepository = orderRepository;
        _timeLimitSettingRepository = timeLimitSettingRepository;
    }

    [Theory]
    [InlineData("2024-09-23 15:07:40", 5, "15", "2024-09-29 15:07:39", "5个工作日")]
    public async Task CalcEndTimeWorkDay_Test(string begin, int count, string busCode, string expiredTime, string timeText)
    {
        var beginTime = DateTime.Parse(begin);
        var result = await _calcExpireTime.CalcEndTime(beginTime,beginTime, ETimeType.WorkDay, count, busCode);
        result.ShouldNotBeNull();
        result.EndTime.ShouldBe(DateTime.Parse(expiredTime));
    }

    [Theory]
    [InlineData("2024-09-25 13:16:33", 5, "15", "2024-10-08 13:16:32", "5个工作日")]
    public async Task CalcEndTimeWorkDayDelay_Test(string begin, int count, string busCode, string expiredTime, string timeText)
    {
        var beginTime = DateTime.Parse(begin);
        var result = await _calcExpireTime.CalcEndTime(beginTime,beginTime, ETimeType.WorkDay, count, 0, 0);
        result.ShouldNotBeNull();
        result.EndTime.ShouldBe(DateTime.Parse(expiredTime));
    }


    [Theory]
    [InlineData("2024-09-04 14:00:00", 2, "10", "2024-09-06 13:59:59", "2024/9/6 10:24:00", "2024/9/5 14:00:00", "2个工作日")]
    [InlineData("2024-09-04 14:01:01", 3, "10", "2024-09-09 14:01:00", "2024/9/6 17:37:01", "2024/9/6 9:31:01", "3个工作日")]
    public async Task CalcEndTime_Test(string begin, int count, string busCode, string expiredTime, string nearlyExpiredTime, string nearlyExpiredTimeOne, string timeText)
    {
        var beginTime = DateTime.Parse(begin);
        var result = await _calcExpireTime.CalcEndTime(beginTime,beginTime, new TimeConfig(count, ETimeType.WorkDay), busCode);
        result.ShouldNotBeNull();
        result.ExpiredTime.ShouldBe(DateTime.Parse(expiredTime));
        result.NearlyExpiredTime.ShouldBe(DateTime.Parse(nearlyExpiredTime));
        result.NearlyExpiredTimeOne.ShouldBe(DateTime.Parse(nearlyExpiredTimeOne));
        result.Count.ShouldBe(count);
        result.TimeText.ShouldBe(timeText);
    }

    [Theory]
    [InlineData("2024-09-04 14:00:00", "CenterToOrg", true, "2024-09-05 14:00:00")]
    [InlineData("2024-10-03 09:23:46", "CenterToCenter", false, "2024-10-12 18:00:00")]
    public async Task CalcExpiredTime_Test(string beginTxt, string flowTxt, bool is24Hour , string expected)
    {
        var beginTime = DateTime.Parse(beginTxt);
        Enum.TryParse(flowTxt, out EFlowDirection flow);
        var inDto = new OrderTimeClacInfo
        {
            Is24HoursComplete = is24Hour,
            FlowDirection = flow,
            AcceptTypeCode = "20"
        };
        var time = await _calcExpireTime.CalcExpiredTime(beginTime,beginTime, flow,inDto);
        time.ShouldNotBeNull();
        time.ExpiredTime.ShouldBe(DateTime.Parse(expected));
    }
  }
