using Leanetec.EConnect.Client.Dto;
using Leanetec.EConnect.Client.Interface;
using Leanetec.EConnect.Domain.Entities;
using MediatR;

namespace Leanetec.EConnect.Client.Order;

public record GetDocumentRequest(string TenantId, int OrderId) : HttpRequest<Response<IEnumerable<OrderDocument>, ProblemDetail>>
{
}

public class GetDocumentRequestHandler : IRequestHandler<GetDocumentRequest, Response<IEnumerable<OrderDocument>, ProblemDetail>>
{
    private readonly IEConnectClient<ProblemDetail> _client;

    public GetDocumentRequestHandler(IEConnectClient<ProblemDetail> client)
    {
        _client = client;
    }

    public async Task<Response<IEnumerable<OrderDocument>, ProblemDetail>> Handle(GetDocumentRequest request, CancellationToken cancel)
    {
        return await _client.GetAsync<IEnumerable<OrderDocument>>(
            $"api/public/v{request.ApiVersion}/econnect/order/document/list",
            new { request.TenantId, request.OrderId },
            cancel
        );
    }
}