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

namespace Web.Api.Endpoints.Forum.Comment;

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

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