using ErsatzTV.Application.Health;
using ErsatzTV.Core.Api.Health;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace ErsatzTV.Controllers.Api;

[ApiController]
public class HealthController(IMediator mediator) : ControllerBase
{
    [HttpGet("/api/v1/health", Name = "GetHealthChecks")]
    [Tags("Health")]
    [EndpointSummary("Get health check results")]
    [EndpointDescription(
        "Results are cached briefly; pass refresh=true to force a fresh run (re-executes ffmpeg-backed checks).")]
    [EndpointGroupName("general")]
    [ProducesResponseType(typeof(List<HealthCheckResponseModel>), StatusCodes.Status200OK)]
    public async Task<List<HealthCheckResponseModel>> GetAll(
        [FromQuery] bool refresh,
        CancellationToken cancellationToken) =>
        await mediator.Send(new GetAllHealthCheckResultsForApi(refresh), cancellationToken);
}
