using NATS.Server.Raft;

namespace NATS.Server.Raft.Tests.Raft;

public class RaftConfigAndStateParityBatch1Tests
{
    [Fact]
    public void RaftState_string_matches_go_labels()
    {
        RaftState.Follower.String().ShouldBe("Follower");
        RaftState.Leader.String().ShouldBe("Leader");
        RaftState.Candidate.String().ShouldBe("Candidate");
        RaftState.Closed.String().ShouldBe("Closed");
    }

    [Fact]
    public void RaftConfig_exposes_go_shape_fields()
    {
        var cfg = new RaftConfig
        {
            Name = "META",
            Store = new object(),
            Log = new object(),
            Track = true,
            Observer = true,
            Recovering = true,
            ScaleUp = true,
        };

        cfg.Name.ShouldBe("META");
        cfg.Store.ShouldNotBeNull();
        cfg.Log.ShouldNotBeNull();
        cfg.Track.ShouldBeTrue();
        cfg.Observer.ShouldBeTrue();
        cfg.Recovering.ShouldBeTrue();
        cfg.ScaleUp.ShouldBeTrue();
    }

    [Fact]
    public void RaftNode_group_defaults_to_id_when_not_supplied()
    {
        using var node = new RaftNode("N1");
        node.GroupName.ShouldBe("N1");
    }

    [Fact]
    public void RaftNode_group_uses_explicit_value_when_supplied()
    {
        using var node = new RaftNode("N1", group: "G1");
        node.GroupName.ShouldBe("G1");
    }

    [Fact]
    public void RaftNode_created_utc_is_set_on_construction()
    {
        var before = DateTime.UtcNow;
        using var node = new RaftNode("N1");
        var after = DateTime.UtcNow;

        node.CreatedUtc.ShouldBeGreaterThanOrEqualTo(before);
        node.CreatedUtc.ShouldBeLessThanOrEqualTo(after);
    }
}
