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

namespace Web.Api.Endpoints.Document;

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

            return ApiResponse.Ok(result);
        })
        .WithTags("Document")
        .AllowAnonymous();
    }
}