using NATS.Client.Core;

namespace NATS.E2E.Tests.Infrastructure;

/// <summary>
/// xUnit fixture that manages a single NATS server process shared across a test collection.
/// </summary>
public sealed class NatsServerFixture : IAsyncLifetime
{
    private NatsServerProcess _server = null!;

    public int Port => _server.Port;

    public string ServerOutput => _server.Output;

    public async Task InitializeAsync()
    {
        _server = new NatsServerProcess();
        await _server.StartAsync();
    }

    public async Task DisposeAsync()
    {
        await _server.DisposeAsync();
    }

    public NatsConnection CreateClient()
    {
        return new NatsConnection(new NatsOpts { Url = $"nats://127.0.0.1:{Port}" });
    }
}
