using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
///
/// Work queue endpoints for each workflow stage.
/// Each queue returns batches filtered by status and sorted by submission time ASC
/// so the oldest pending item is always at the top.
///
[ApiController]
[Route("api/v1/work-queue")]
[Produces("application/json")]
[Authorize]
public class WorkQueueController : ControllerBase
{
private readonly IWorkQueueService _workQueue;
public WorkQueueController(IWorkQueueService workQueue)
{
_workQueue = workQueue;
}
///
/// Returns batches in PendingVerification status, sorted by submittedAt ASC.
/// Verifiers use this queue to pick the next batch to verify.
///
[HttpGet("verification")]
[Authorize(Roles = "VERIFIER,CLINICAL_APPROVER,ADMINISTRATOR")]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status200OK)]
public async Task GetVerificationQueue(
[FromQuery] int page = 1,
[FromQuery] int pageSize = 20,
[FromQuery] string sortBy = "updatedAt",
[FromQuery] string sortDirection = "asc")
{
var result = await _workQueue.GetVerificationQueueAsync(page, pageSize, sortBy, sortDirection);
return Ok(ApiResponse.Ok(result));
}
///
/// Returns batches awaiting or currently in data entry.
/// Includes batches in Uploaded (awaiting assignment), InEntry (being entered),
/// and Rejected (returned for re-entry) statuses.
/// Data entry clerks use this queue to find their next assignment.
///
[HttpGet("entry")]
[Authorize(Roles = "DATA_ENTRY_CLERK,ADMINISTRATOR")]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status200OK)]
public async Task GetEntryQueue(
[FromQuery] int page = 1,
[FromQuery] int pageSize = 20,
[FromQuery] string sortBy = "updatedAt",
[FromQuery] string sortDirection = "asc")
{
var result = await _workQueue.GetEntryQueueAsync(page, pageSize, sortBy, sortDirection);
return Ok(ApiResponse.Ok(result));
}
///
/// Returns batches in AwaitingClinicalApproval status, sorted by submittedAt ASC.
/// Clinical approvers use this queue to find batches that need clinical sign-off
/// after verification. Only batch types configured to require clinical approval
/// in site config will appear here.
///
[HttpGet("clinical-approval")]
[Authorize(Roles = "CLINICAL_APPROVER,ADMINISTRATOR")]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status200OK)]
public async Task GetClinicalApprovalQueue(
[FromQuery] int page = 1,
[FromQuery] int pageSize = 20,
[FromQuery] string sortBy = "updatedAt",
[FromQuery] string sortDirection = "asc")
{
var result = await _workQueue.GetClinicalApprovalQueueAsync(page, pageSize, sortBy, sortDirection);
return Ok(ApiResponse.Ok(result));
}
///
/// Returns aggregate work queue health metrics for the supervisor dashboard.
///
[HttpGet("overview")]
[Authorize(Roles = "ADMINISTRATOR")]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ApiResponse