using System; using System.Threading; using System.Threading.Tasks; using Jellyfin.Plugin.MovieNight.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace Jellyfin.Plugin.MovieNight.Controllers; /// /// Admin endpoints for the MovieNight plugin. /// [ApiController] [Authorize] [Route("MovieNight")] public class MovieNightController : ControllerBase { private readonly MovieNightBackendClient _backendClient; /// /// Initializes a new instance of the class. /// /// Backend client. public MovieNightController(MovieNightBackendClient backendClient) { _backendClient = backendClient; } /// /// Returns plugin status. /// /// Status response. [HttpGet("Status")] public ActionResult GetStatus() { var configuration = Plugin.Instance?.Configuration; return new MovieNightPluginStatus( Enabled: configuration?.Enabled ?? false, BackendBaseUrl: configuration?.BackendBaseUrl ?? string.Empty, PeriodicSyncEnabled: configuration?.EnablePeriodicSync ?? false, PlaybackEventsEnabled: configuration?.EnablePlaybackEvents ?? false, SyncIntervalMinutes: configuration?.SyncIntervalMinutes ?? 30); } /// /// Tests backend connectivity. /// /// Cancellation token. /// Connection result. [HttpPost("TestConnection")] public async Task> TestConnection(CancellationToken cancellationToken) { return await _backendClient.TestConnectionAsync(cancellationToken).ConfigureAwait(false); } /// /// Triggers backend sync. /// /// Cancellation token. /// Backend response. [HttpPost("Sync")] public async Task> Sync(CancellationToken cancellationToken) { return await _backendClient.TriggerSyncAsync(cancellationToken).ConfigureAwait(false); } /// /// Gets backend sync state. /// /// Cancellation token. /// Backend response. [HttpGet("SyncState")] public async Task> SyncState(CancellationToken cancellationToken) { return await _backendClient.GetSyncStateAsync(cancellationToken).ConfigureAwait(false); } } /// /// MovieNight plugin status response. /// /// Whether integration is enabled. /// Backend base URL. /// Whether periodic sync is enabled. /// Whether playback events are enabled. /// Sync interval in minutes. public sealed record MovieNightPluginStatus( bool Enabled, string BackendBaseUrl, bool PeriodicSyncEnabled, bool PlaybackEventsEnabled, int SyncIntervalMinutes);