using Microsoft.AspNetCore.Mvc;
using w4c_workflows.Filters;
using w4c_workflows.Services.Quota;
namespace w4c_workflows.Controllers;
///
/// Per-tenant workflow execution quota. GET returns the current period's
/// usage (drives the counter on the Workflows page); POST reset zeroes it
/// for the current period (admin / support). Authenticated with the tenant's
/// operator key, like every other control-plane endpoint.
///
[ApiController]
[Route("api/workflows/quota")]
public class WorkflowQuotaController : ControllerBase
{
private readonly WorkflowQuotaService _quota;
public WorkflowQuotaController(WorkflowQuotaService quota)
{
_quota = quota;
}
private string TenantId => (string?)HttpContext.Items["TenantId"]
?? throw new InvalidOperationException("TenantId not resolved by auth middleware");
/// Current execution usage against this tenant's monthly limit.
[HttpGet]
[RequireScope("read")]
public async Task Get(CancellationToken ct)
{
return Ok(await _quota.GetAsync(TenantId, ct));
}
/// Resets the current period's execution counter to zero.
[HttpPost("reset")]
[RequireScope("manage")]
public async Task Reset(CancellationToken ct)
{
return Ok(await _quota.ResetAsync(TenantId, ct));
}
}