using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
namespace Jellyfin.Plugin.SRFPlay.Services.Interfaces;
///
/// Interface for proxying SRF Play streams and managing authentication.
///
public interface IStreamProxyService
{
///
/// Registers a stream for deferred authentication (authenticates on first playback request).
/// Use this when browsing to avoid wasting 30-second tokens before the user clicks play.
///
/// The item ID.
/// The unauthenticated stream URL.
/// The SRF URN for this content.
/// Whether this is a livestream.
void RegisterStreamDeferred(string itemId, string unauthenticatedUrl, string? urn = null, bool isLiveStream = false);
///
/// Gets stream metadata for an item (URN and isLiveStream flag).
///
/// The item ID.
/// A tuple of (URN, IsLiveStream), or null if not found.
(string? Urn, bool IsLiveStream)? GetStreamMetadata(string itemId);
///
/// Gets the authenticated URL for an item.
///
/// The item ID.
/// Cancellation token.
/// The authenticated URL, or null if not found or expired.
Task GetAuthenticatedUrlAsync(string itemId, CancellationToken cancellationToken = default);
///
/// Fetches and rewrites an HLS manifest to use proxy URLs.
///
/// The item ID.
/// The base proxy URL.
/// Cancellation token.
/// The rewritten manifest content.
Task GetRewrittenManifestAsync(string itemId, string baseProxyUrl, CancellationToken cancellationToken = default);
///
/// Fetches a segment from the original source.
///
/// The item ID.
/// The segment path.
/// The original query string from the request (preserves segment-specific parameters like timestamps).
/// Cancellation token.
/// The segment content as bytes.
Task GetSegmentAsync(string itemId, string segmentPath, string? queryString = null, CancellationToken cancellationToken = default);
///
/// Fetches a segment from the original source as a streaming response.
/// Returns the HttpResponseMessage for streaming directly to the client, reducing TTFB.
/// The caller is responsible for disposing the response.
///
/// The item ID.
/// The segment path.
/// The original query string from the request.
/// Cancellation token.
/// The HTTP response for streaming, or null if not found.
Task GetSegmentStreamAsync(string itemId, string segmentPath, string? queryString = null, CancellationToken cancellationToken = default);
///
/// Rewrites URLs in a variant (sub) manifest to point to the proxy.
///
/// The variant manifest content.
/// The base proxy URL (without query params).
/// Query parameters to append to rewritten URLs (e.g., "?token=abc").
/// The rewritten manifest content.
string RewriteVariantManifestUrls(string manifestContent, string baseProxyUrl, string queryParams);
///
/// Cleans up old and expired stream mappings.
///
void CleanupOldMappings();
}