using MediatR;
using Web.Api.Common;

namespace Web.Api.Endpoints.Forum.Board;

internal sealed class Search : IEndpoint
{
    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        app.MapGet("api/forum/boards", async (
            ISender sender,
            CancellationToken ct,
            int? boardGroupID = null,
            string? boardGroupCode = null,
            string? keyword = null,
            int page = 1,
            ushort perPage = 20
        ) =>
        {
            var query = new Application.Features.Api.Forum.Board.Search.Query(boardGroupID, boardGroupCode, keyword, page, perPage);

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