using ErsatzTV.Application.Libraries;
using ErsatzTV.Core.Api.Libraries;
using ErsatzTV.Core.Metadata;
using MediatR;
using NSubstitute;
using NUnit.Framework;
using Shouldly;

namespace ErsatzTV.Tests.Application.Libraries;

[TestFixture]
public class GetLibraryScanStatusHandlerTests
{
    [Test]
    public async Task Handle_Should_Return_Active_Scans()
    {
        var mediator = Substitute.For<IMediator>();
        var scannerProxyService = new ScannerProxyService(mediator);
        Guid scanId = scannerProxyService.StartScan(42)
            .Match(
                Some: id => id,
                None: () => throw new AssertionException("Expected scan to start"));
        await scannerProxyService.Progress(scanId, 62.5m);

        var handler = new GetLibraryScanStatusHandler(scannerProxyService);

        List<LibraryScanStatusResponseModel> result =
            await handler.Handle(new GetLibraryScanStatus(), CancellationToken.None);

        result.ShouldBe([new LibraryScanStatusResponseModel(42, 62.5m)]);
    }
}
