using FastEndpoints;
using TaxBaik.Application.Services;

namespace TaxBaik.Web.Endpoints.Inquiry;

public class GetPagedEndpoint : Endpoint<InquiryQuery, InquiryPagedResponse>
{
    private readonly InquiryService _inquiryService;

    public GetPagedEndpoint(InquiryService inquiryService)
    {
        _inquiryService = inquiryService;
    }

    public override void Configure()
    {
        Get("/api/inquiry");
        Policies("Bearer");
    }

    public override async Task HandleAsync(InquiryQuery request, CancellationToken ct)
    {
        var (inquiries, total) = await _inquiryService.GetPagedAsync(request.Page, request.PageSize);
        await SendAsync(new InquiryPagedResponse
        {
            Data = inquiries.Cast<object>().ToList(),
            Total = total,
            Page = request.Page,
            PageSize = request.PageSize
        }, 200, cancellation: ct);
    }
}
