using Newtonsoft.Json;
using Nostr.Client.Json;
using Nostr.Client.Messages;
using StackExchange.Redis;

namespace NostrServices.Services.EventHandlers;

public class RedisStreamPublisher : IEventHandler
{
    private readonly IDatabase _redis;

    public RedisStreamPublisher(IDatabase redis)
    {
        _redis = redis;
    }

    public async ValueTask HandleEvent(NostrEvent ev)
    {
        var json = JsonConvert.SerializeObject(ev, NostrSerializer.Settings);
        await _redis.PublishAsync("event-stream", json);
    }
}
