using Nalu.Web.Models;
using Nalu.Web.Services;

namespace Nalu.Web.Endpoints;

public static class ValidatorsEndpoints
{
    public static void MapValidatorsEndpoints(this WebApplication app)
    {
        app.MapGet("/v1/validators", (ValidatorLoader loader) =>
        {
            var validators = loader.LoadAll().Select(v => new ValidatorInfo
            {
                Id = v.Id,
                Endpoint = v.Endpoint,
                McpTool = v.McpTool,
                Description = !string.IsNullOrEmpty(v.McpDescription)
                    ? v.McpDescription.Split('.')[0].Trim()
                    : v.Description,
                Version = v.Version,
                Languages = v.Languages
            }).ToList();

            return Results.Ok(new { validators });
        })
        .WithName("ListValidators")
        .WithSummary("Lista todos os validadores disponíveis")
        .WithTags("Validators")
        .WithOpenApi();
    }
}
