using Leanetec.EConnect.Client.Order;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace Leanetec.EConnect.Proxy.Controllers;

[Route("api/[controller]")]
[ApiController]
public class OrderController : ControllerBase
{
    private readonly IMediator _mediator;

    public OrderController(IMediator mediator)
    {
        _mediator = mediator;
    }

    [HttpGet("document")]
    public async Task<IActionResult> GetDocument([FromQuery] GetDocumentRequest request, CancellationToken cancel)
    {
        var res = await _mediator.Send(request, cancel);
        if(res.Ok)
        {
            return res.Data is null || !res.Data.Any() ? NotFound() : Ok(res.Data);
        }
        else
        {
            return StatusCode(res?.Error?.Status ?? 500, res?.Error);
        }
    }
}