using FastEndpoints;
using KArtSell.Modules.ModelOperations.FeedbackLoop;

namespace KArtSell.Modules.ModelOperations.Features.GetModelFeedbackLoop;

public sealed class Endpoint : EndpointWithoutRequest<Response>
{
    public override void Configure()
    {
        Get("/model-operations/feedback-loop");
        Roles("Quant", "Risk", "Compliance", "Operations", "Administrator");
        Summary(x =>
        {
            x.Summary = "Returns the governed continuous model feedback plan.";
            x.Description = "This endpoint exposes evaluation/proposal stages only. It cannot activate a model or submit an order.";
        });
    }

    public override Task HandleAsync(CancellationToken ct)
    {
        var stages = ModelFeedbackPlan.Stages.Select(x => new ModelFeedbackStageResponse(
            x.Order, x.StageCode, x.OperationCode, x.Name, x.AutomationBoundary,
            x.RequiredEvidence, x.HumanDecision, x.FailureAction)).ToArray();
        return Send.OkAsync(new Response(ModelFeedbackPlan.Boundary, stages), ct);
    }
}
