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

namespace Web.Api.Endpoints.Forum.Comment;

internal sealed class Search : IEndpoint
{
    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        app.MapGet("api/forum/comments", async (
            ISender sender,
            CancellationToken ct,
            int? boardID = null,
            int? postID = null,
            int? search = null,
            string? keyword = null,
            string? startAt = null,
            string? endAt = null,
            bool? isDeleted = null,
            int page = 1,
            ushort perPage = 20
        ) =>
        {
            var query = new Application.Features.Api.Forum.Comment.Search.Query(
                boardID, postID, search, keyword, startAt, endAt, isDeleted, page, perPage
            );

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