using System.Threading;
using Jellyfin.Plugin.SRFPlay.Api.Models;
using Jellyfin.Plugin.SRFPlay.Services.Interfaces;
using MediaBrowser.Common.Api;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Plugin.SRFPlay.Controllers;
///
/// Administrative maintenance actions for the SRF Play plugin.
///
[ApiController]
[Route("Plugins/SRFPlay/Maintenance")]
[Authorize(Policy = Policies.RequiresElevation)]
public class MaintenanceController : ControllerBase
{
private readonly ILogger _logger;
private readonly IResumeCleanupService _resumeCleanupService;
///
/// Initializes a new instance of the class.
///
/// The logger.
/// The resume cleanup service.
public MaintenanceController(
ILogger logger,
IResumeCleanupService resumeCleanupService)
{
_logger = logger;
_resumeCleanupService = resumeCleanupService;
}
///
/// Clears stale SRF Play resume points from every user's "Continue Watching" row.
///
///
/// When true, clears every SRF Play resume point instead of only the stale ones.
///
/// The cancellation token.
/// A summary of what was inspected and cleared.
[HttpPost("ResumePoints/Cleanup")]
[ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult CleanupResumePoints(
[FromQuery] bool clearAll,
CancellationToken cancellationToken)
{
_logger.LogInformation("Manual Continue Watching cleanup requested (clearAll: {ClearAll})", clearAll);
return Ok(_resumeCleanupService.Cleanup(clearAll, cancellationToken));
}
}