using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using ROLAC.API.DTOs.MealAttendance;
using ROLAC.API.Services;
namespace ROLAC.API.Controllers;
[ApiController]
[Route("api/meal-attendance")]
public class MealAttendanceController : ControllerBase
{
private readonly IMealAttendanceService _svc;
public MealAttendanceController(IMealAttendanceService svc) => _svc = svc;
/// Today's live counts. Public — feeds the volunteer counter page on first load.
[HttpGet("today")]
[AllowAnonymous]
public async Task GetToday()
=> Ok(await _svc.GetOrCreateAsync(_svc.ServiceDay));
/// Daily counts within a date range, for the back-office dashboard chart.
[HttpGet]
[Authorize]
public async Task GetRange([FromQuery] DateOnly from, [FromQuery] DateOnly to)
=> Ok(await _svc.GetRangeAsync(from, to));
/// Overwrite a specific Sunday's counts (back-office editor). Authenticated only.
[HttpPut("{date}")]
[Authorize]
public async Task SetCounts(DateOnly date, [FromBody] SetAttendanceRequest body)
=> Ok(await _svc.SetCountsAsync(date, body.Adult, body.Youth, body.Kid));
}