using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XYY.Core.Standard.AliYun;
using XYY.Data.Standard.Order;
using XYY.Model.Standard.Channel;
using XYY.Model.Standard.Order;
using XYY.Service.Standard.ChannelApi.Base;

namespace XYY.Service.Standard.ChannelApi.LTEmpty
{
    class Api : IBaseApi
    {
        public Task<List<BagDeclareErrosResult>> BagDeclare(BagDeclareRequest bagDeclareRequest)
        {
            throw new NotImplementedException();
        }
        public string ServiceName => "ST0001";

        readonly IOrderRepository _orderRepository;
        private IAliYunPostFileSerivce _aliYunPostFileSerivce;
        public Api(IOrderRepository orderRepository, IAliYunPostFileSerivce aliYunPostFileSerivce)
        {
            _orderRepository = orderRepository;
            _aliYunPostFileSerivce = aliYunPostFileSerivce;
        }

        public async Task<UploadResult> DataUpload(Order_Order order, List<Order_OrderGoods> goods, Logistics_Channel channel, ExtendArg arg)
        {
            var querys = await _orderRepository.QueryAsync(x => x.SystemNo == order.CustomerOrderNo 
            && x.OrderStatus > 0);
            if (querys.Count() == 0)
            {
                throw new OrderApiException("找不到订单信息", order.SystemNo, order.ChannelId, OrderApiMethod.下单);
            }
            else
            {
                var dto = querys.First();
                return new UploadResult
                {
                    TrackingNumber = dto.TrackingNumber,
                    TransferNumner = dto.TransferNumber,
                    IsSuccess = true,
                    IsTransfer = false,
                    DownloadUrl = _aliYunPostFileSerivce.GetPublicCDN(dto.ServiceLabelUrl)
                };
            }
        }

        public Task<byte[]> DrawPdfLabel(UploadResult result, Logistics_Channel channel, Order_Order order, List<Order_OrderGoods> orderGoods)
        {
            throw new NotImplementedException();
        }
         
        public Task<List<string>> Confims(List<OrderConfimRequest> order, Logistics_Channel channel)
        {
            throw new NotImplementedException();
        }

        public void CannelOrders(List<string> systemNO)
        {
            throw new NotImplementedException();
        }

        public Task<string> GetTrackingNumber(string SystemNo, string TrackingNumber, string ServiceOrderNo, Logistics_Channel channel)
        {
            throw new NotImplementedException();
        }
        public void CannelOrdersByModel(logistics_ChannelCancel logistics_ChannelCancel)
        {
            throw new NotImplementedException();
        }
    }
}
