using ZB.MOM.WW.MxGateway.Contracts.Proto;

namespace ZB.MOM.WW.MxGateway.Server.Sessions;

/// <summary>
///     The result of a reconnect/resume attach
///     (<see cref="GatewaySession.AttachEventSubscriberWithReplay"/>): the live
///     subscriber lease plus the replay batch and resume watermarks snapshotted atomically
///     with the registration, so the replay→live handoff has no gap and no duplicate.
/// </summary>
/// <param name="Lease">
///     The live event subscriber lease. Disposing it unregisters the distributor subscriber
///     and decrements the session's active-subscriber count, exactly as a fresh attach.
/// </param>
/// <param name="ReplayedEvents">
///     Retained events with worker sequence strictly greater than the requested
///     <c>afterSequence</c>, in ascending order. These must be yielded (after the optional
///     gap sentinel) before live events. Never null; empty when nothing newer is retained.
/// </param>
/// <param name="Gap">
///     <see langword="true"/> when events between the requested <c>afterSequence</c> and the
///     oldest retained event were already evicted, so the client missed unrecoverable events.
///     When <see langword="true"/> the caller emits a <c>ReplayGap</c> sentinel before the
///     replay batch.
/// </param>
/// <param name="OldestAvailableSequence">
///     The oldest worker sequence still retained and replayable; <c>0</c> when nothing is
///     retained. Populates the <c>ReplayGap.oldest_available_sequence</c> field. Meaningful
///     only when <paramref name="Gap"/> is <see langword="true"/>.
/// </param>
/// <param name="LiveResumeSequence">
///     The worker sequence the live channel must resume strictly after: the highest replayed
///     sequence, or the requested <c>afterSequence</c> when nothing was replayed. The caller
///     applies this as the per-subscriber live filter so any event both replayed and fanned
///     into the live channel is dropped exactly once (no duplicate) while every newer event
///     is delivered (no gap).
/// </param>
public readonly record struct EventSubscriberReplayAttachment(
    IEventSubscriberLease Lease,
    IReadOnlyList<MxEvent> ReplayedEvents,
    bool Gap,
    ulong OldestAvailableSequence,
    ulong LiveResumeSequence);
