using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SolutionErp.Application.Contracts;

namespace SolutionErp.Api.Controllers;

[ApiController]
[Route("api/workflows")]
[Authorize(Policy = "Workflows.Read")]
public class WorkflowsController(IMediator mediator) : ControllerBase
{
    [HttpGet]
    public async Task<ActionResult<WorkflowAdminOverviewDto>> Overview(CancellationToken ct)
        => Ok(await mediator.Send(new GetWorkflowAdminOverviewQuery(), ct));

    [HttpPost]
    [Authorize(Policy = "Workflows.Create")]
    public async Task<ActionResult<object>> Create([FromBody] CreateWorkflowDefinitionCommand cmd, CancellationToken ct)
    {
        var id = await mediator.Send(cmd, ct);
        return Ok(new { id });
    }
}
