using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Controller.MediaEncoding;
///
/// Provides a durable store for HLS transcoding session state, enabling
/// HA recovery and lease-based ownership between pods.
///
public interface ITranscodeSessionStore
{
///
/// Attempts to retrieve a transcoding session by its play session identifier.
///
/// The play session identifier.
/// A cancellation token.
///
/// The if it exists and its lease has not expired;
/// otherwise null.
///
Task TryGetAsync(string playSessionId, CancellationToken cancellationToken = default);
///
/// Attempts to take over ownership of an existing session by claiming the lease for
/// . Takeover succeeds only when the session exists and
/// its current lease has already expired.
///
/// The play session identifier.
/// The name of the pod attempting to claim ownership.
/// A cancellation token.
///
/// true if the takeover succeeded (the claiming pod now holds the lease);
/// false if the session does not exist, its lease is still valid, or another
/// concurrent caller already claimed it.
///
Task TryTakeoverAsync(string playSessionId, string claimingPod, CancellationToken cancellationToken = default);
///
/// Persists a new or updated transcoding session.
///
/// The session to store.
/// A cancellation token.
/// A representing the asynchronous operation.
Task SetAsync(TranscodeSession session, CancellationToken cancellationToken = default);
///
/// Renews the lease for an existing session, extending its
/// by the store's configured lease duration.
///
/// The play session identifier.
/// A cancellation token.
/// A representing the asynchronous operation.
Task RenewLeaseAsync(string playSessionId, CancellationToken cancellationToken = default);
///
/// Removes a transcoding session from the store.
///
/// The play session identifier.
/// A cancellation token.
/// A representing the asynchronous operation.
Task DeleteAsync(string playSessionId, CancellationToken cancellationToken = default);
///
/// Returns all currently active transcoding sessions from the store.
///
/// A cancellation token.
///
/// An enumerable of objects representing all active sessions.
/// Returns an empty enumerable if no sessions are active or if the store cannot be reached.
///
Task> GetActiveSessionsAsync(CancellationToken cancellationToken = default);
///
/// Persists a live stream session record so that takeover pods can identify and close
/// streams that were opened on a pod that has since crashed or been evicted.
///
/// The live stream session to store.
/// A cancellation token.
/// A representing the asynchronous operation.
Task SetLiveStreamAsync(LiveStreamSession session, CancellationToken cancellationToken = default);
///
/// Attempts to retrieve a live stream session by its live stream identifier and the
/// session or play-session identifier that owns it.
///
/// The live stream identifier.
/// The session identifier or play-session identifier.
/// A cancellation token.
///
/// The if it exists; otherwise null.
///
Task TryGetLiveStreamAsync(string liveStreamId, string sessionIdOrPlaySessionId, CancellationToken cancellationToken = default);
///
/// Removes the live stream session record for the given live stream and session identifier.
/// This is called when the stream is closed, either by the owning pod or a takeover pod.
///
/// The live stream identifier.
/// The session identifier or play-session identifier.
/// A cancellation token.
/// A representing the asynchronous operation.
Task DeleteLiveStreamAsync(string liveStreamId, string sessionIdOrPlaySessionId, CancellationToken cancellationToken = default);
}