using OF_DL.Services;

namespace OF_DL.Gui.Services;

internal sealed class AvaloniaProgressReporter(
    Action<long> reportAction,
    Func<bool> isCancellationRequested,
    CancellationToken cancellationToken) : IProgressReporter
{
    public CancellationToken CancellationToken { get; } = cancellationToken;

    public void ReportProgress(long increment)
    {
        if (isCancellationRequested())
        {
            throw new OperationCanceledException("Operation canceled by user.");
        }

        if (increment > 0)
        {
            reportAction(increment);
        }
    }
}
