using Hotline.Application.StatisticalReport.CallReport;
using Hotline.Share.Dtos.CallCenter;
using Hotline.Share.Enums.CallCenter;
using Hotline.Share.Requests;
using Hotline.Share.Tools;
using Shouldly;
using SqlSugar.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hotline.Application.Tests.Application;
public class ZiGongCallReportApplicationTest
{
    private readonly ZiGongCallReportApplication _ziGongCallReportApplication;
    private CancellationToken cancellation;

    public ZiGongCallReportApplicationTest(ZiGongCallReportApplication ziGongCallReportApplication)
    {
        _ziGongCallReportApplication = ziGongCallReportApplication;
        cancellation = new CancellationToken();
    }

    [Fact]
    public async Task QueryCallsDetailInTotal_Test()
    {
        var inDto = new BiQueryCallsDto
        {
            StartTime = "2024-10-30".ObjToDate(),
            EndTime = "2024-10-30 23:59:59".ObjToDate()
        };
        var (total, items) = await _ziGongCallReportApplication.QueryCallsDetailInTotalAsync(inDto, false);
        total.ShouldNotBe(0);
    }

    [Fact]
    public async Task QuerySeatCall_Test()
    {
        var inDto = new ReportRequiredPagedRequest
        {
            StartTime = "2024-06-01".ObjToDate(),
            EndTime = DateTime.Now
        };

        var result = await _ziGongCallReportApplication.QuerySeatCallAsync(inDto, cancellation);
        result.ShouldNotBeNull();
    }

    [Theory]
    [InlineData(null, null, null, null)]
    [InlineData(null, "19136073037", null, null)]
    [InlineData(null, null, "67387546", null)]
    [InlineData("20240805000001", null, null, null)]
    [InlineData(null, null, null, "From")]
    public async Task QueryCallsStatisticsDetail_Test(string? orderNo, string? fromNo, string? toNo, string? endBy)
    {
        return;
        var inDto = new QueryCallsStatisticsDetailInDto
        {
            StartTime = "2024-10-30".ObjToDate(),
            EndTime = "2024-10-30 23:59:59".ObjToDate(),
            OrderNo = orderNo,
            FromNo = fromNo,
            ToNo = toNo,
            EndBy = endBy?.ToEnum<EEndBy>()
        };
        var (total, items) = await _ziGongCallReportApplication.QueryCallsStatisticsDetailAsync(inDto, cancellation);
        total.ShouldNotBe(0);
        items.Any(m => m.OrderNo.NotNullOrEmpty()).ShouldBeTrue();
        items.Any(m => m.OrderTitle.NotNullOrEmpty()).ShouldBeTrue();
        if (fromNo != null)
            items.Any(m => m.FromNo != fromNo).ShouldBeFalse();
        if (toNo != null)
            items.Any(m => m.ToNo != toNo).ShouldBeFalse();
        if (orderNo != null)
            items.Any(m => m.OrderNo != orderNo).ShouldBeFalse();
        if (endBy != null)
            items.Any(m => m.EndBy != inDto.EndBy).ShouldBeFalse();
    }

    [Theory]
    [InlineData()]
    public async Task QueryCallsDetailStatistics_Test()
    {
        var inDto = new StartEndTimeDto 
        { 
            StartTime = "2024-07-29".ObjToDate(),
            EndTime = "2024-07-29 23:59:59".ObjToDate(),
        };
        var result = await _ziGongCallReportApplication.QueryCallsDetailStatisticsAsync(inDto, cancellation);
        result.Any(m => m.InConnectionRate.IsNullOrEmpty()).ShouldBeFalse();
        result.ShouldNotBeNull();
    }
}
