using OF_DL.Models.Downloads;

namespace OF_DL.CLI;

public interface ICajetanDownloadEventHandler : IDownloadEventHandler
{
    void OnMessage(string message, string color);
}

public class CajetanDownloadEventHandler : ICajetanDownloadEventHandler
{
    private readonly SpectreDownloadEventHandler _eventHandler = new();

    public void OnContentFound(string contentType, int mediaCount, int objectCount)
        => _eventHandler.OnContentFound(contentType, mediaCount, objectCount);

    public void OnDownloadComplete(string contentType, DownloadResult result)
        => _eventHandler.OnDownloadComplete(contentType, result);

    public void OnMessage(string message)
        => _eventHandler.OnMessage(message);

    public void OnMessage(string message, string color)
        => AnsiConsole.MarkupLine($"[{color.ToLowerInvariant()}]{Markup.Escape(message)}[/]");

    public void OnNoContentFound(string contentType)
        => _eventHandler.OnNoContentFound(contentType);

    public void OnPurchasedTabUserComplete(string username, int paidPostCount, int paidMessagesCount)
        => _eventHandler.OnPurchasedTabUserComplete(username, paidPostCount, paidMessagesCount);

    public void OnScrapeComplete(TimeSpan elapsed)
        => _eventHandler.OnScrapeComplete(elapsed);

    public void OnUserComplete(string username, CreatorDownloadResult result)
        => _eventHandler.OnUserComplete(username, result);

    public void OnUserStarting(string username) { }

    public Task<T> WithProgressAsync<T>(string description, long maxValue, bool showSize, Func<IProgressReporter, Task<T>> work)
        => _eventHandler.WithProgressAsync(description, maxValue, showSize, work);

    public Task<T> WithStatusAsync<T>(string statusMessage, Func<IStatusReporter, Task<T>> work)
        => _eventHandler.WithStatusAsync(statusMessage, work);
}
