using DigitalData.TaskFlow.API.Contracts.Workflows;
using DigitalData.TaskFlow.API.Contracts.Common;
using DigitalData.TaskFlow.Application.Features.Workflows.Commands.CloseWorkflow;
using DigitalData.TaskFlow.Application.Features.Workflows.Queries.GetWorkflows;
using MediatR;
using Microsoft.AspNetCore.Mvc;
namespace DigitalData.TaskFlow.API.Controllers;
///
/// Provides workflow read and close endpoints.
///
[ApiController]
[Route("api/workflows")]
public sealed class WorkflowsController(ISender sender) : ControllerBase
{
///
/// Returns open workflows for a WISAG user identifier.
///
/// WISAG user identifier.
/// Cancellation token.
/// Workflow response envelope grouped by source.
[HttpGet("{wisagId:int}")]
[ProducesResponseType(typeof(WorkflowsResponse), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(MetaOnlyResponse), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(MetaOnlyResponse), StatusCodes.Status401Unauthorized)]
[ProducesResponseType(typeof(MetaOnlyResponse), StatusCodes.Status500InternalServerError)]
public async Task> GetAsync(
[FromRoute] int wisagId,
CancellationToken cancellationToken)
{
var response = await sender.Send(new GetWorkflowsQuery(wisagId), cancellationToken);
var sources = response.Data?.Sources
.Cast