using ErsatzTV.Core.Api.Libraries;
using ErsatzTV.Core.Interfaces.Metadata;
using ErsatzTV.Core.Metadata;

namespace ErsatzTV.Application.Libraries;

public class GetLibraryScanStatusHandler(IScannerProxyService scannerProxyService)
    : IRequestHandler<GetLibraryScanStatus, List<LibraryScanStatusResponseModel>>
{
    public Task<List<LibraryScanStatusResponseModel>> Handle(
        GetLibraryScanStatus request,
        CancellationToken cancellationToken)
    {
        List<LibraryScanStatusResponseModel> result = scannerProxyService.GetActiveScans()
            .Select(scan => new LibraryScanStatusResponseModel(scan.LibraryId, scan.Progress))
            .ToList();

        return Task.FromResult(result);
    }
}
