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

namespace Web.Api.Endpoints.Banner;

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

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

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