using Edge.Core.Domain.FccOrderInfo.Input;
using Edge.Core.Domain.FccOrderInfo.Output;
using FccLite.Web.Services.FccOrderInfo;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;

namespace FccLite.Web.Controller
{
    [Route("qrFueling/order")]
    [ApiController]
    public class OrderInfoController : ControllerBase
    {
        static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
        private readonly IOrderInfoService _orderInfoService;
        public OrderInfoController(IOrderInfoService orderInfoService)
        {
            this._orderInfoService = orderInfoService;
        }

        [HttpPost("getPage")]
        public async Task<IActionResult> GetPage(OrderInfoPageInput orderInfoPageInput)
        {
            logger.Info($"order get page:{JsonConvert.SerializeObject(orderInfoPageInput)}");
            OrderInfoOutput orderInfoOutput = await _orderInfoService.GetPage(orderInfoPageInput);
            return Ok(orderInfoOutput);
        }

        [HttpPost("getPagePrepay")]
        public async Task<IActionResult> GetPagePrepay(OrderInfoPageInput orderInfoPageInput)
        {
            logger.Info($"order get page:{JsonConvert.SerializeObject(orderInfoPageInput)}");
            PrepayOrderInfoOutput prepayOrderInfoOutput = await _orderInfoService.GetPrepayPage(orderInfoPageInput);
            return Ok(prepayOrderInfoOutput);
        }


        [HttpPost("downloadOrderAfterPayOrderExcel")]
        public async Task<IActionResult> DownloadOrderAfterPayOrderExcel(OrderInfoPageInput orderInfoPageInput)
        {
            logger.Info($"download after pay order excel:{JsonConvert.SerializeObject(orderInfoPageInput)}");
            byte[] fileBytes = await _orderInfoService.DownloadAfterPayOrderExcel(orderInfoPageInput);
            return File(fileBytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "orders.xlsx");
        }

        [HttpPost("downloadOrderPrepayOrderExcel")]
        public async Task<IActionResult> DownloadOrderPrePayOrderExcel(OrderInfoPageInput orderInfoPageInput)
        {
            logger.Info($"download after pay order excel:{JsonConvert.SerializeObject(orderInfoPageInput)}");
            byte[] fileBytes = await _orderInfoService.DownloadPrepayOrderExcel(orderInfoPageInput);
            return File(fileBytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "orders.xlsx");
        }

    }
}
