using System.Threading.Tasks.Dataflow;
using Nostr.Client.Messages;
using Nostr.Client.Requests;
using NostrRelay;

namespace PayForReactions;

public class ZapperRelay : INostrRelay, IDisposable
{
    private readonly ReactionQueue _queue;

    public ZapperRelay(ReactionQueue queue)
    {
        _queue = queue;
    }

    public ValueTask<bool> AcceptConnection(NostrClientContext context)
    {
        return ValueTask.FromResult(true);
    }

    public async IAsyncEnumerable<NostrEvent> HandleRequest(NostrClientContext context, NostrRequest req)
    {
        yield break;
    }

    public async ValueTask<HandleEventResponse> HandleEvent(NostrClientContext context, NostrEvent ev)
    {
        _queue.Queue.Post(ev);
        return new(true, "");
    }

    public void Dispose()
    {
    }
}
