using Web.Api.Common;
using Web.Api.Extensions;
using Application.Abstractions.Messaging;

namespace Web.Api.Endpoints.Forum.Board;

internal sealed class Meta : IEndpoint
{
    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        app.MapGet("api/forum/boards/{boardID}/meta", async (
            int boardID,
            ISender sender,
            CancellationToken ct
        ) =>
        {
            var result = await sender.Send(new Application.Features.Api.Forum.BoardMeta.Get.Query(boardID), ct);

            return result.Match(data => ApiResponse.Ok(data), CustomResults.Problem);
        })
        .WithTags("Forum")
        .AllowAnonymous();
    }
}