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

namespace Leanetec.EConnect.Client.Order;

public record PostDocumentRequest(string TenantId, int OrderId, StreamContent Content) : HttpRequest<Response<ProblemDetail>>
{
}

public class PostDocumentRequestHandler : IRequestHandler<PostDocumentRequest, Response<ProblemDetail>>
{
    private readonly IEConnectClient<ProblemDetail> _client;

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

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