using FastEndpoints;
using TaxBaik.Application.Services;

namespace TaxBaik.Web.Endpoints.Inquiry;

public class GetByIdEndpoint : Endpoint<EmptyRequest, object>
{
    private readonly InquiryService _inquiryService;

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

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

    public override async Task HandleAsync(EmptyRequest _, CancellationToken ct)
    {
        var id = Route<int>("id");
        var inquiry = await _inquiryService.GetByIdAsync(id);
        if (inquiry == null)
        {
            ThrowError("문의를 찾을 수 없습니다.", statusCode: 404);
        }

        await SendAsync(inquiry, 200, cancellation: ct);
    }
}
