using Knot.Modules.Settings.Application.Settings.Queries;
using Knot.Shared.Kernel;
using MediatR;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;

namespace Knot.Modules.Settings.Presentation.Endpoints;

public static class SettingsEndpoints
{
    public static void MapSettingsEndpoints(this WebApplication app)
    {
        app.MapGet("api/config", async (ISender sender, CancellationToken ct) =>
        {
            var result = await sender.Send(new GetPublicConfigQuery(), ct);
            return result.IsSuccess ? Results.Ok(result.Value) : Results.BadRequest(result.Error);
        });
    }
}
