using NostrRelay;
using NostrServices.Client;
using PayForReactions;

var builder = WebApplication.CreateBuilder(args);

var config = builder.Configuration.GetSection("Config").Get<Config>()!;
builder.Services.AddSingleton(config);

builder.Services.AddMemoryCache();
builder.Services.AddHttpClient();
builder.Services.AddTransient<Lnurl>();
builder.Services.AddTransient<AlbyApi>();
builder.Services.AddTransient<ZapperRelay>();
builder.Services.AddTransient<NostrServicesClient>();
builder.Services.AddSingleton<NostrStore>(svc =>
{
    var logger = svc.GetRequiredService<ILogger<NostrStore>>();
    return new NostrStore("./data", logger);
});

builder.Services.AddSingleton<ReactionQueue>();
builder.Services.AddHostedService<ReactionQueueWorker>();

var host = builder.Build();

host.UseWebSockets();
host.MapRelay<ZapperRelay>("/", new RelayDocument()
{
    Name = "wss://reactions.v0l.io",
    Description = "Zapping server for Kieran's paid reactions",
    SupportedNips = [1],
    Software = "PayForReactions (https://git.v0l.io/Kieran/NostrServices)",
    Limitation = new()
    {
        RestrictedWrites = true,
        AuthRequired = false,
        PaymentRequired = false
    }
});

host.Run();
