using NATS.Server.JetStream.Models;
using StorageType = NATS.Server.JetStream.Models.StorageType;

namespace NATS.Server.JetStream.Storage;

// Go: server/store.go:357
/// <summary>
/// Persists and retrieves durable consumer state: delivery progress, ack floor,
/// pending messages, and redelivery counts. One store instance per consumer.
/// Mirrors Go's ConsumerStore interface.
/// </summary>
public interface IConsumerStore
{
    // Go: ConsumerStore.SetStarting — initialise the starting stream sequence for a new consumer
    void SetStarting(ulong sseq);

    // Go: ConsumerStore.UpdateStarting — update the starting sequence after a reset
    void UpdateStarting(ulong sseq);

    // Go: ConsumerStore.Reset — reset state to a given stream sequence
    void Reset(ulong sseq);

    // Go: ConsumerStore.HasState — returns true if any persisted state exists
    bool HasState();

    // Go: ConsumerStore.UpdateDelivered — record a new delivery (dseq=consumer seq, sseq=stream seq,
    //     dc=delivery count, ts=Unix nanosecond timestamp)
    void UpdateDelivered(ulong dseq, ulong sseq, ulong dc, long ts);

    // Go: ConsumerStore.UpdateAcks — record an acknowledgement (dseq=consumer seq, sseq=stream seq)
    void UpdateAcks(ulong dseq, ulong sseq);

    // Go: ConsumerStore.Update — overwrite the full consumer state in one call
    void Update(ConsumerState state);

    // Go: ConsumerStore.State — return a snapshot of current consumer state
    ConsumerState State();

    // Go: ConsumerStore.BorrowState — return state without copying (caller must not retain beyond call)
    ConsumerState BorrowState();

    // Go: ConsumerStore.EncodedState — return the binary-encoded state for replication
    byte[] EncodedState();

    // Go: ConsumerStore.Type — the storage type backing this store (File or Memory)
    StorageType Type();

    // Go: ConsumerStore.Stop — flush and close the store without deleting data
    void Stop();

    // Go: ConsumerStore.Delete — stop the store and delete all persisted state
    void Delete();

    // Go: ConsumerStore.StreamDelete — called when the parent stream is deleted
    void StreamDelete();
}
