using System.Diagnostics.CodeAnalysis;

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

/// <summary>
/// Registry for managing active gateway sessions.
/// </summary>
public interface ISessionRegistry
{
    /// <summary>
    /// Total number of sessions (open or closed) in the registry.
    /// </summary>
    int Count { get; }

    /// <summary>
    /// Number of sessions currently in an active (open) state.
    /// </summary>
    int ActiveCount { get; }

    /// <summary>
    /// Attempts to add a session to the registry; returns false if session ID already exists.
    /// </summary>
    /// <param name="session">Session to add.</param>
    /// <returns>True if added; false if session ID already exists.</returns>
    bool TryAdd(GatewaySession session);

    /// <summary>
    /// Attempts to retrieve a session by ID; returns false if not found.
    /// </summary>
    /// <param name="sessionId">Identifier of the session.</param>
    /// <param name="session">The retrieved session, if found.</param>
    /// <returns>True if found; false otherwise.</returns>
    bool TryGet(string sessionId, [MaybeNullWhen(false)] out GatewaySession session);

    /// <summary>
    /// Attempts to remove a session by ID; returns false if not found.
    /// </summary>
    /// <param name="sessionId">Identifier of the session to remove.</param>
    /// <param name="session">The removed session, if found.</param>
    /// <returns>True if removed; false if not found.</returns>
    bool TryRemove(string sessionId, [MaybeNullWhen(false)] out GatewaySession session);

    /// <summary>
    /// Returns a snapshot of all sessions in the registry.
    /// </summary>
    /// <returns>A read-only collection of all sessions.</returns>
    IReadOnlyCollection<GatewaySession> Snapshot();
}
