using System.Text;
using Beam.Abstractions;
using Microsoft.Playwright;

namespace Beam.Playwright.Strategies;

internal class PageDownloadStrategy : IDownloadStrategy {
    public async Task DownloadToStream(string url, int bufferSize, Stream destinationStream, IProgress<IDownloadReport> progress, IPage page,
        CancellationToken ct) {

        var source = await page.InnerHTMLAsync("html", new PageInnerHTMLOptions() { Strict = false });
        var bytes = Encoding.UTF8.GetBytes(source);
        await destinationStream.WriteAsync(bytes, ct);
    }
}