using FastEndpoints;
using TaxBaik.Application.Services;

namespace TaxBaik.Web.Endpoints.Client;

public class GetByIdEndpoint : Endpoint<EmptyRequest, object>
{
    private readonly ClientService _clientService;

    public GetByIdEndpoint(ClientService clientService)
    {
        _clientService = clientService;
    }

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

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

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