namespace NexusReader.UI.Shared.Services;

public sealed class ReaderInteractionService : IReaderInteractionService
{
    public event Func<string, Task>? OnNodeSelected;
    public event Func<string, Task>? OnScrollToBlockRequested;
    public event Func<string, Task>? OnHighlightBlockRequested;
    public event Func<string, string, SelectionCoordinates, Task>? OnTextSelected;
    public event Func<Task>? OnAssistantRequested;

    public async Task NotifyNodeSelected(string nodeId)
    {
        if (OnNodeSelected != null) await OnNodeSelected(nodeId);
    }

    public async Task RequestScrollToBlock(string blockId)
    {
        if (OnScrollToBlockRequested != null) await OnScrollToBlockRequested(blockId);
    }

    public async Task RequestHighlightBlock(string blockId)
    {
        if (OnHighlightBlockRequested != null) await OnHighlightBlockRequested(blockId);
    }

    public async Task NotifyTextSelected(string text, string blockId, SelectionCoordinates coords)
    {
        if (OnTextSelected != null) await OnTextSelected(text, blockId, coords);
    }

    public async Task RequestAssistant()
    {
        if (OnAssistantRequested != null) await OnAssistantRequested();
    }
}
