using System.Text.Json;
using NATS.Server.Events;

namespace NATS.Server.Monitoring.Tests.Events;

public class EventServerInfoCapabilityParityBatch1Tests
{
    [Fact]
    public void ServerCapability_flags_match_expected_values()
    {
        ((ulong)ServerCapability.JetStreamEnabled).ShouldBe(1UL << 0);
        ((ulong)ServerCapability.BinaryStreamSnapshot).ShouldBe(1UL << 1);
        ((ulong)ServerCapability.AccountNRG).ShouldBe(1UL << 2);
    }

    [Fact]
    public void EventServerInfo_capability_methods_set_and_read_flags()
    {
        var info = new EventServerInfo();

        info.SetJetStreamEnabled();
        info.SetBinaryStreamSnapshot();
        info.SetAccountNRG();

        info.JetStream.ShouldBeTrue();
        info.JetStreamEnabled().ShouldBeTrue();
        info.BinaryStreamSnapshot().ShouldBeTrue();
        info.AccountNRG().ShouldBeTrue();
    }

    [Fact]
    public void ServerID_serializes_with_name_host_id_fields()
    {
        var payload = new ServerID
        {
            Name = "srv-a",
            Host = "127.0.0.1",
            Id = "N1",
        };

        var json = JsonSerializer.Serialize(payload);
        json.ShouldContain("\"name\":\"srv-a\"");
        json.ShouldContain("\"host\":\"127.0.0.1\"");
        json.ShouldContain("\"id\":\"N1\"");
    }
}
