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

namespace SolutionErp.Api.Controllers;

// Versioned workflow admin cho module Duyệt NCC (PE). Reuse policy
// "Workflows.Read" + "Workflows.Create" giống Contract — admin có quyền
// quản lý cả 2 nhóm workflow (HĐ + PE).
[ApiController]
[Route("api/pe-workflows")]
[Authorize(Policy = "Workflows.Read")]
public class PeWorkflowsController(IMediator mediator) : ControllerBase
{
    [HttpGet]
    public async Task<ActionResult<PeWorkflowAdminOverviewDto>> Overview(CancellationToken ct)
        => Ok(await mediator.Send(new GetPeWorkflowAdminOverviewQuery(), ct));

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