using Web.Api.Common;
using Web.Api.Extensions;
using MediatR;

namespace Web.Api.Endpoints.Forum.Board;

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

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