using MediatR;
using Web.Api.Common;

namespace Web.Api.Endpoints.Faq;

internal sealed class Items : IEndpoint
{
    public sealed record Request(
        string Code
    );

    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        app.MapPost("api/faq/items", async (
            Request request,
            ISender sender,
            CancellationToken ct
        ) => {
            var query = new Application.Features.Api.Faq.Item.GetByCode.Query(request.Code);

            return ApiResponse.Ok(
                await sender.Send(query, ct)
            );
        })
        .WithTags("Faq")
        .AllowAnonymous();
    }
}