namespace NATS.Server.JetStream.Storage;

// Go: server/store.go:162
/// <summary>
/// Full state snapshot for a stream, returned by IStreamStore.State() and
/// IStreamStore.FastState(). Matches Go's StreamState struct, including optional
/// per-subject message counts, deleted sequence lists, and consumer count.
/// </summary>
public record struct StreamState
{
    // Go: StreamState.Msgs — total number of messages in the stream
    public ulong Msgs { get; set; }

    // Go: StreamState.Bytes — total bytes stored
    public ulong Bytes { get; set; }

    // Go: StreamState.FirstSeq — sequence number of the oldest message
    public ulong FirstSeq { get; set; }

    // Go: StreamState.FirstTime — wall-clock time of the oldest message
    public DateTime FirstTime { get; set; }

    // Go: StreamState.LastSeq — sequence number of the newest message
    public ulong LastSeq { get; set; }

    // Go: StreamState.LastTime — wall-clock time of the newest message
    public DateTime LastTime { get; set; }

    // Go: StreamState.NumSubjects — count of distinct subjects in the stream
    public int NumSubjects { get; set; }

    // Go: StreamState.Subjects — per-subject message counts (populated on demand)
    public Dictionary<string, ulong>? Subjects { get; set; }

    // Go: StreamState.NumDeleted — number of interior gaps (deleted sequences)
    public int NumDeleted { get; set; }

    // Go: StreamState.Deleted — explicit list of deleted sequences (populated on demand)
    public ulong[]? Deleted { get; set; }

    // Go: StreamState.Lost (LostStreamData) — sequences that were lost due to storage corruption
    public LostStreamData? Lost { get; set; }

    // Go: StreamState.Consumers — number of consumers attached to the stream
    public int Consumers { get; set; }
}

// Go: server/store.go:189
/// <summary>
/// Describes messages lost due to storage-level corruption.
/// Mirrors Go's LostStreamData struct.
/// </summary>
public sealed class LostStreamData
{
    // Go: LostStreamData.Msgs — sequences of lost messages
    public ulong[]? Msgs { get; set; }

    // Go: LostStreamData.Bytes — total bytes of lost data
    public ulong Bytes { get; set; }
}

// Go: server/store.go:178
/// <summary>
/// Compact state for a single subject filter within a stream.
/// Used by IStreamStore.FilteredState() and SubjectsState().
/// Mirrors Go's SimpleState struct.
/// </summary>
public record struct SimpleState
{
    // Go: SimpleState.Msgs — number of messages matching the filter
    public ulong Msgs { get; set; }

    // Go: SimpleState.First — first sequence number matching the filter
    public ulong First { get; set; }

    // Go: SimpleState.Last — last sequence number matching the filter
    public ulong Last { get; set; }
}
