//
// Copyright (c) PlaceholderCompany. All rights reserved.
//
namespace Jellyfin.Server.Implementations.Clustering
{
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Database.Implementations.Entities;
///
/// Interface for managing Jellyfin instance registration and lifecycle.
///
public interface IInstanceRegistry
{
///
/// Gets the unique identifier for the current instance.
///
Guid CurrentInstanceId { get; }
///
/// Registers the current instance in the database.
///
/// The hostname of the instance.
/// The process ID of the instance.
/// The HTTP port.
/// The HTTPS port (optional).
/// The Jellyfin version.
/// Instance capabilities (JSON).
/// Cancellation token.
/// A task representing the asynchronous operation.
Task RegisterInstanceAsync(
string hostname,
int processId,
int httpPort,
int? httpsPort,
string version,
string? capabilities,
CancellationToken cancellationToken = default);
///
/// Updates the heartbeat timestamp for the current instance.
///
/// Cancellation token.
/// A task representing the asynchronous operation.
Task UpdateHeartbeatAsync(CancellationToken cancellationToken = default);
///
/// Marks the current instance as shutdown in the database.
///
/// Cancellation token.
/// A task representing the asynchronous operation.
Task ShutdownInstanceAsync(CancellationToken cancellationToken = default);
///
/// Gets all active instances from the database.
///
/// Cancellation token.
/// List of active instances.
Task> GetActiveInstancesAsync(CancellationToken cancellationToken = default);
///
/// Gets a specific instance by ID.
///
/// The instance ID.
/// Cancellation token.
/// The instance, or null if not found.
Task GetInstanceAsync(Guid instanceId, CancellationToken cancellationToken = default);
///
/// Removes stale instances from the database.
///
/// Time after which an instance is considered stale.
/// Cancellation token.
/// Number of instances removed.
Task CleanupStaleInstancesAsync(TimeSpan staleThreshold, CancellationToken cancellationToken = default);
///
/// Checks if the current instance is the primary instance.
///
/// Cancellation token.
/// True if this instance is primary.
Task IsPrimaryInstanceAsync(CancellationToken cancellationToken = default);
}
}