using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using XYY.Core.Standard.PDF;
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.CaiNiao
{
    public class Api : IBaseApi, IUItidelApi, ITrunkLineApi
    {
        public string ServiceName => "CaiNiao";
        private string ActioinUrl => "/gateway/link.do";//正式地址
                                                        //private string ActioinUrl => "http://prelink.cainiao.com/gateway/link.do";//测试地址
        IOrder_OrderPrintQtyRepository _order_OrderPrintQtyRepository;
        public Api(IOrder_OrderPrintQtyRepository order_OrderPrintQtyRepository)
        {
            _order_OrderPrintQtyRepository = order_OrderPrintQtyRepository;
        }
        public void CannelOrders(List<string> systemNO)
        {
            throw new NotImplementedException();
        }
        public async Task<List<BagDeclareErrosResult>> BagDeclare(BagDeclareRequest bagDeclareRequest)
        { throw new NotImplementedException(); }
        public void CannelOrdersByModel(logistics_ChannelCancel logistics_ChannelCancel)
        {
            throw new NotImplementedException();
        }
        public Task<string> GetTrackingNumber(string SystemNo, string TrackingNumber, string ServiceOrderNo, Logistics_Channel channel)
        {
            throw new NotImplementedException();
        }
        public async Task CannelBag(CannelIBBagParam param) { throw new NotImplementedException(); }
        public async Task<UploadResult> DataUpload(Order_Order order, List<Order_OrderGoods> goods, Logistics_Channel channel, ExtendArg arg)
        {
            if (string.IsNullOrWhiteSpace(order.ReceiverPhone))
            {
                order.ReceiverPhone = channel.DefaultPhone;
            }
            var body = await ConvertRequestBody(order, goods, channel, arg.AgentIOSS);
            string json = JsonConvert.SerializeObject(body);
            RestClient client = new RestClient(channel.ApiHost + ActioinUrl);
            RestRequest request = new RestRequest(Method.POST);
            string sign = Md5(json, channel.ApiSecret, "utf-8");
            request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
            request.AddParameter("msg_type", "cnge.order.create");
            request.AddParameter("logistic_provider_id", channel.ApiKey);
            request.AddParameter("data_digest", sign);
            request.AddParameter("logistics_interface", json);
            request.AddParameter("to_code", "CNGCP-OPEN");
            var response = client.Execute(request);
            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var result = JsonConvert.DeserializeObject<DataUploadResult>(response.Content);
                if (result.success)
                {
                    var uploadResult = new UploadResult
                    {
                        IsSuccess = true,
                        ServiceOrderNumber = result.data.orderCode,
                        TrackingNumber = result.data.trackingNumber,
                        destinationCode = order.CreateOrderChannelId == 541 ? "X" : "Y",
                    };
                    return uploadResult;
                }
                else
                {
                    throw new Exception($"CN下单[{body.outOrderId}]失败:{result.errorMsg}");
                }
            }
            else
            {
                throw new Exception($"CN下单[{body.outOrderId}]异常:{response.Content ?? response.ErrorMessage}");
            }
        }
        public async Task<byte[]> DrawPdfLabel(UploadResult result, Logistics_Channel channel, Order_Order order, List<Order_OrderGoods> orderGoods)
        {
            int rQty = 1;
        A:
            var body = new PdfLabelRequest() { orderCode = result.ServiceOrderNumber };
            string json = JsonConvert.SerializeObject(body);
            RestClient client = new RestClient(channel.ApiHost + ActioinUrl);
            RestRequest request = new RestRequest(Method.POST);
            string sign = Md5(json, channel.ApiSecret, "utf-8");
            request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
            request.AddParameter("msg_type", "cnge.waybill.get");
            request.AddParameter("logistic_provider_id", channel.ApiKey);
            request.AddParameter("data_digest", sign);
            request.AddParameter("logistics_interface", json);
            request.AddParameter("to_code", "CGOP");
            var response = client.Execute(request);
            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var pdfResult = JsonConvert.DeserializeObject<PdfLabelResult>(response.Content);
                if (pdfResult.success)
                {
                    var bytes = Convert.FromBase64String(pdfResult.data.waybillPdfData);
                    return bytes;
                }
                else
                {
                    if (pdfResult.errorMsg == "系统错误" && rQty < 3)
                    {
                        rQty++;
                        System.Threading.Thread.Sleep(1000);
                        goto A;
                    }
                    throw new Exception($"CN获取面单失败:{pdfResult.errorMsg}");
                }
            }
            else
            {
                throw new Exception($"CN获取面单失败:{response.Content ?? response.ErrorMessage}");
            }
        }
        public async Task<List<string>> Confims(List<OrderConfimRequest> order, Logistics_Channel channel)
        {
            var list = new List<string>();
            foreach (var item in order)
            {
                try
                {
                    PackageConfimRequest packageConfimRequest = new PackageConfimRequest();
                    packageConfimRequest.packageMeasureParam = new PackageMeasureParam()
                    {
                        weight = (long)item.OPWeight
                    };
                    packageConfimRequest.option = new Option()
                    {
                        updatePickupInfo = false,//默认不更新揽收信息
                        updatePackageMeasure = true,
                    };
                    packageConfimRequest.orderCode = item.ServicesOrderNo;

                    string json = JsonConvert.SerializeObject(packageConfimRequest);
                    RestClient client = new RestClient(channel.ApiHost + ActioinUrl);
                    RestRequest request = new RestRequest(Method.POST);
                    string sign = Md5(json, channel.ApiSecret, "utf-8");
                    request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
                    request.AddParameter("msg_type", "cnge.order.update");
                    request.AddParameter("logistic_provider_id", channel.ApiKey);
                    request.AddParameter("data_digest", sign);
                    request.AddParameter("logistics_interface", json);
                    request.AddParameter("to_code", "CNGCP-OPEN");
                    var response = client.Execute(request);
                    if (response.StatusCode == System.Net.HttpStatusCode.OK)
                    {
                        var pdfResult = JsonConvert.DeserializeObject<PackageConfimResult>(response.Content);
                        if (!pdfResult.success && !pdfResult.errorMsg.Contains("包裹已组大包"))//排除更换箱子的异常
                        {
                            list.Add(item.TrackingNumber);
                        }
                    }
                    else
                    {
                        list.Add(item.TrackingNumber);
                    }
                }
                catch (Exception ex)
                {
                    string message = ex.Message;
                    Console.WriteLine(message);
                    list.Add(item.TrackingNumber);
                }
            }
            return list;
        }
        public async Task<ChannelBagLabelResult> GetChannelBagLabel(ChannelBagLabelParam param)
        {
            if (param.Orders.Count() > 1000)
            {
                throw new Exception($"CN获取大包面单失败,每箱上限1000单，箱号：{param.Box.BoxNumber},超出上限");
            };
            if (param.BoxDetails.Any(x => !x.IsConfim || !string.IsNullOrEmpty(x.Message)))
            {
                throw new Exception($"箱号:{param.Box.BoxNumber}中存在未确认或确认重量失败的订单!无法获取大包面单！");
            }
            BigbagRequst bigbagRequst = new BigbagRequst() { weight = param.Orders.Sum(x => x.OPWeight) };
            bigbagRequst.handoverParam = new HandoverParam()
            {
                name = "范先生",//param.Channel.SenderName,//
                mobilePhone = param.Channel.SenderPhone,
                country = "中国",//param.Channel.SenderCountryCode,//
                state = "广东",//param.Channel.SenderState,//
                city = "广州",//param.Channel.SenderCity,//
                detailAddress = "广州市白云北大道创意园218号建鹏路1598号", //param.Channel.SenderStreet,// 
                zipCode = param.Channel.SenderZipCode,
            };
            List<string> orderCodeLists = new List<string>();
            foreach (var item in param.Orders)
            {
                //OrderCodeList orderCode = new OrderCodeList() { orderCode = item.ServicesOrderNo };
                orderCodeLists.Add(item.ServicesOrderNo);
            }
            bigbagRequst.orderCodeList = orderCodeLists;
            var bigbagResult = new BigbagResult();
            var pdfResult = new PdfLabelResult();
            #region 创建大包
            string json = JsonConvert.SerializeObject(bigbagRequst);
            RestClient client = new RestClient(param.Channel.ApiHost + ActioinUrl);
            RestRequest request = new RestRequest(Method.POST);
            string sign = Md5(json, param.Channel.ApiSecret, "utf-8");
            request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
            request.AddParameter("msg_type", "cnge.bigbag.create");
            request.AddParameter("logistic_provider_id", param.Channel.ApiKey);
            request.AddParameter("data_digest", sign);
            request.AddParameter("logistics_interface", json);
            request.AddParameter("to_code", "CNPMS");
            var response = client.Execute(request);
            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                bigbagResult = JsonConvert.DeserializeObject<BigbagResult>(response.Content);
                if (!bigbagResult.success)
                {
                    throw new Exception($"CN创建大包失败:{bigbagResult.errorMsg}");
                }
            }
            else
            {
                throw new Exception($"CN创建大包失败:{response.Content ?? response.ErrorMessage}");
            }
            #endregion
            #region 获取大包面单
            var body = new PdfLabelRequest() { orderCode = bigbagResult.data.bigBagCode, waybillType = "256" };
            string pdfjson = JsonConvert.SerializeObject(body);
            RestClient pdfclient = new RestClient(param.Channel.ApiHost + ActioinUrl);
            RestRequest pdfrequest = new RestRequest(Method.POST);
            string pdfsign = Md5(pdfjson, param.Channel.ApiSecret, "utf-8");
            pdfrequest.AddHeader("Content-Type", "application/x-www-form-urlencoded");
            pdfrequest.AddParameter("msg_type", "cnge.waybill.get");
            pdfrequest.AddParameter("logistic_provider_id", param.Channel.ApiKey);
            pdfrequest.AddParameter("data_digest", pdfsign);
            pdfrequest.AddParameter("logistics_interface", pdfjson);
            pdfrequest.AddParameter("to_code", "CGOP");
            var pdfresponse = pdfclient.Execute(pdfrequest);
            if (pdfresponse.StatusCode == System.Net.HttpStatusCode.OK)
            {
                pdfResult = JsonConvert.DeserializeObject<PdfLabelResult>(pdfresponse.Content);
                if (!pdfResult.success)
                {
                    throw new Exception($"CN获取面单失败:{pdfResult.errorMsg}");
                }
            }
            else
            {
                throw new Exception($"CN获取面单失败:{response.Content ?? response.ErrorMessage}");
            }
            #endregion
            var bytes = Convert.FromBase64String(pdfResult.data.waybillPdfData);
            var newBytes = PDFHelper.Watermark(bytes, param.Box.BoxNumber, 1, 50, 30, 15, iTextSharp.text.BaseColor.BLACK);
            var base64 = Convert.ToBase64String(newBytes);
            ChannelBagLabelResult result = new ChannelBagLabelResult
            {
                Label = base64,
                BoxNumber = param.Box.BoxNumber,
                ChannelBagNumber = bigbagResult.data.bigBagTrackingNumber,
                DestinationPortCode = "",
                DestinationTurnOverCode = "",
                ServiceCode = bigbagResult.data.bigBagCode
            };
            return result;
        }

        public async Task<ChannelTrunkLineResult> DeliveryPush(ChannelTrunkLineParam param)
        {
            var body = await ConvertDeliveryPushRequestBody(param);
            var converter = new IsoDateTimeConverter
            {
                DateTimeFormat = "yyyy-MM-dd HH:mm:ss.fffZ"
            };
            string json = JsonConvert.SerializeObject(body, converter);
            RestClient client = new RestClient(param.Channel.ApiHost + ActioinUrl);
            RestRequest request = new RestRequest(Method.POST);
            string sign = Md5(json, param.Channel.ApiSecret, "utf-8");
            request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
            request.AddParameter("msg_type", "cnge.airline.receive");
            request.AddParameter("logistic_provider_id", param.Channel.ApiKey);
            request.AddParameter("data_digest", sign);
            request.AddParameter("logistics_interface", json);
            request.AddParameter("to_code", "CGOP");
            var response = client.Execute(request);
            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var result = JsonConvert.DeserializeObject<TransportResult>(response.Content);
                if (result.success)
                {
                    return new ChannelTrunkLineResult() { IsSuccess = true };
                }
                else
                {
                    throw new Exception($"CN交航推送失败:{result.errorMsg}");
                }
            }
            else
            {
                throw new Exception($"CN交航推送失败:{response.Content ?? response.ErrorMessage}");
            }
        }
        public async Task<ChannelTrunkLineResult> ArrivePush(ChannelTrunkLineParam param)
        {
            if (!param.TrunkLine.Ata.HasValue || !param.TrunkLine.Atd.HasValue) { throw new Exception("实际到达与实际起飞时间必须填写！"); }
            var body = new ArriveRequest()
            {
                mawbNo = param.TrunkLine.LadingBillNumber,
                ata = Convert.ToDateTime(param.TrunkLine.Ata),
                atd = Convert.ToDateTime(param.TrunkLine.Atd),
                flightNo = string.IsNullOrEmpty(param.TrunkLine.ArriveFlightNo) ? param.TrunkLine.FlightNo : param.TrunkLine.ArriveFlightNo,
                timeZone = param.TrunkLine.TimeZone,
            };
            var converter = new IsoDateTimeConverter
            {
                DateTimeFormat = "yyyy-MM-dd HH:mm:ss.fffZ"
            };
            string json = JsonConvert.SerializeObject(body, converter);
            RestClient client = new RestClient(param.Channel.ApiHost + ActioinUrl);
            RestRequest request = new RestRequest(Method.POST);
            string sign = Md5(json, param.Channel.ApiSecret, "utf-8");
            request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
            request.AddParameter("msg_type", "cnge.airline.arrive");
            request.AddParameter("logistic_provider_id", param.Channel.ApiKey);
            request.AddParameter("data_digest", sign);
            request.AddParameter("logistics_interface", json);
            request.AddParameter("to_code", "CGOP");
            var response = client.Execute(request);
            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var result = JsonConvert.DeserializeObject<TransportResult>(response.Content);
                if (result.success)
                {
                    return new ChannelTrunkLineResult() { IsSuccess = true };
                }
                else
                {
                    throw new Exception($"CN到达推送失败:{result.errorMsg}");
                }
            }
            else
            {
                throw new Exception($"CN到达推送失败:{response.Content ?? response.ErrorMessage}");
            }
        }

        private string Md5(string content, string keys, string charset)
        {
            string sign = null;
            content = content + keys;
            try
            {
                using (var md = System.Security.Cryptography.MD5.Create())
                {
                    var bytes = Encoding.GetEncoding(charset).GetBytes(content);
                    var hash = md.ComputeHash(bytes);
                    sign = Convert.ToBase64String(hash);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            return sign;
        }
        private async Task<DataUploadRequest> ConvertRequestBody(Order_Order order, List<Order_OrderGoods> goods, Logistics_Channel channel, bool AgentIOSS)
        {
            System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"^.*?(?=\d)");

            var match = regex.Match(order.ReceiverStreet);
            if (!match.Success && order.ReceiverCountryCode == "DE")
            {
                throw new Exception("德国专线地址内需要包含街道与数字门牌号");
            }

            if (order.ReceiverStreet.Length > 128) { throw new Exception("收件人地址不得超过128个字符！"); }
            if (order.ReceiverCountryCode == "US")
            {
                string[] Remote = new string[] { "AK", "HI", "GU", "AS", "MP", "PR", "VI", "AE", "AP" };

                Dictionary<string, string> pairs = new Dictionary<string, string>
                {
                    { "Washington", "WA" },
                    { "Oregon", "OR" },
                    { "California", "CA" },
                    { "Nevada", "NV" },
                    { "Idaho", "ID" },
                    { "Utah", "UT" },
                    { "Arizona", "AZ" },
                    { "Montana", "MT" },
                    { "Wyoming", "WY" },
                    { "Colorado", "CO" },
                    { "New Mexico", "NM" },
                    { "Wisconsin", "WI" },
                    { "Illinois", "IL" },
                    { "Tennessee", "TN" },
                    { "Mississippi", "MS" },
                    { "Michigan", "MI" },
                    { "Indiana", "IN" },
                    { "Kentucky", "KY" },
                    { "Alabama", "AL" },
                    { "Ohio", "OH" },
                    { "West Virginia", "WV" },
                    { "Virginia", "VA" },
                    { "North Carolina", "NC" },
                    { "South Carolina", "SC" },
                    { "Georgia", "GA" },
                    { "North Dakota", "ND" },
                    { "South Dakota", "SD" },
                    { "Nebraska", "NE" },
                    { "Kansas", "KS" },
                    { "Oklahoma", "OK" },
                    { "Texas", "TX" },
                    { "Minnesota", "MN" },
                    { "Iowa", "IA" },
                    { "Missouri", "MO" },
                    { "Arkansas", "AR" },
                    { "Louisiana", "LA" },
                    { "Florida", "FL" },
                    { "Pennsylvania", "PA" },
                    { "New York", "NY" },
                    { "Washington D. C.", "DC" },
                    { "Maryland", "MD" },
                    { "Delaware", "DE" },
                    { "New Jersey", "NJ" },
                    { "Connecticut", "CT" },
                    { "Rhode Island", "RI" },
                    { "Massachusetts", "MA" },
                    { "Maine", "ME" },
                    { "New Hampshire", "NH" },
                    { "Vermont", "VT" }
                };

                if (!pairs.Keys.Any(x => x.Equals(order.ReceiverState, StringComparison.CurrentCultureIgnoreCase))
                        && !pairs.Values.Any(x => x.Equals(order.ReceiverState, StringComparison.CurrentCultureIgnoreCase))
                        )
                {
                    if (pairs.Keys.Any(x => x.Equals(order.ReceiverCity, StringComparison.CurrentCultureIgnoreCase)))
                    {
                        string state = order.ReceiverState;
                        order.ReceiverState = pairs.Where(x => x.Key.Equals(order.ReceiverCity, StringComparison.CurrentCultureIgnoreCase)).First().Value;
                        order.ReceiverCity = state;
                    }
                    else if (pairs.Values.Any(x => x.Equals(order.ReceiverCity, StringComparison.CurrentCultureIgnoreCase)))
                    {
                        string state = order.ReceiverState;
                        order.ReceiverState = order.ReceiverCity;
                        order.ReceiverCity = order.ReceiverState;
                    }
                    else
                    {
                        throw new Exception("CN-美国必须传入标准的州名或州简写");
                    }
                }
                else if (pairs.Keys.Any(x => x.Equals(order.ReceiverState, StringComparison.CurrentCultureIgnoreCase)))
                {
                    order.ReceiverState = pairs.Where(x => x.Key.Equals(order.ReceiverState, StringComparison.CurrentCultureIgnoreCase)).First().Value;
                }
                if (Remote.Any(x => x.Equals(order.ReceiverState, StringComparison.CurrentCultureIgnoreCase)))
                {
                    throw new Exception("美国该地区不支持派送");
                }
            }
            DataUploadRequest dataUploadRequest = new DataUploadRequest()
            {
                outOrderId = order.SystemNo + "_" + _order_OrderPrintQtyRepository.GetPackagePrintQty(order.SystemNo),
            };
            dataUploadRequest.receiverParam = new ReceiverParam()
            {
                zipCode = order.ReceiverZipCode,
                mobilePhone = order.ReceiverPhone,
                city = order.ReceiverCity,
                countryCode = order.ReceiverCountryCode,
                name = order.ReceiverName,
                detailAddress = order.ReceiverStreet,
                telephone = order.ReceiverPhone,
                state = order.ReceiverState,
                email = order.ReceiverEmail,
            };
            dataUploadRequest.senderParam = new SenderParam()
            {
                name = channel.SenderName,
                zipCode = channel.SenderZipCode,
                countryCode = channel.SenderCountryCode,
                state = channel.SenderState,
                city = channel.SenderCity,
                detailAddress = channel.SenderStreet,
            };
            dataUploadRequest.solutionParam = new SolutionParam();
            dataUploadRequest.solutionParam.solutionCode = channel.ServiceChannelCode.Split(";")[0];
            if (channel.ServiceChannelCode.Split(";").Count() >= 3)//德国专线会有承运商信息，所以是3个
            {
                dataUploadRequest.solutionParam.customerChooseCarrierParam = new CustomerChooseCarrierParam()
                {
                    carrierCode = channel.ServiceChannelCode.Split(";")[2]
                };
                dataUploadRequest.solutionParam.importCustomsParam = new ImportCustomsParam()
                {
                    //taxNumber = "IM2500000320"
                };
                if (!string.IsNullOrEmpty(order.ioss))
                {
                    dataUploadRequest.solutionParam.importCustomsParam.taxNumber = order.ioss;
                }
                else if (AgentIOSS)
                {
                    dataUploadRequest.solutionParam.importCustomsParam.taxNumber = "IM2760000742";
                }
                dataUploadRequest.solutionParam.cainiaoCustomsParam = new CainiaoCustomsParam() { whetherNeed = true };
            }
            if (channel.ServiceChannelCode.Split(";").Count() == 4
               && channel.ServiceChannelCode.Split(";")[3] == "whetherNeed")
            {
                dataUploadRequest.solutionParam.extraDeliveryeParam = new extraDeliveryeParam { whetherNeed = true };
            }
            PackageParams packageParams = new PackageParams()
            {
                //packageParam = new PackageParam()
                //{
                weight = order.CustomerWeight,
                itemParams = new List<ItemParams>(),
                //}
            };


            var goodsWeight = (int)Math.Floor(order.CustomerWeight / (double)goods.Sum(x => x.Quantity));
            if (goods.Any(x => x.Weight == 0))
            {
                goods.ForEach(x => { x.Weight = goodsWeight; });
            }
            dataUploadRequest.packageParams = new List<PackageParams>();
            foreach (var item in goods)
            {
                ItemParams itemParams = new ItemParams()
                {
                    //itemParam = new ItemParam()
                    //{
                    quantity = item.Quantity,
                    englishName = item.EnName,
                    chineseName = item.CnName,
                    unitPrice = Convert.ToInt32(item.DeclareFee * 100),//单位分
                    unitPriceCurrency = item.DeclareCurrency,
                    hscode = item.HsCode,
                    weight = item.Weight,
                    //}
                };
                packageParams.itemParams.Add(itemParams);
            }
            dataUploadRequest.packageParams.Add(packageParams);
            dataUploadRequest.sourceHandoverParam = new SourceHandoverParam() { type = "PORT", code = channel.ServiceChannelCode.Split(";")[1] };
            return dataUploadRequest;
        }
        private async Task<TransportRequest> ConvertDeliveryPushRequestBody(ChannelTrunkLineParam param)
        {
            TransportRequest transportRequest = new TransportRequest() { mawbNo = param.TrunkLine.LadingBillNumber };
            transportRequest.airlineParam = new AirlineParam()
            {
                flightNo = param.TrunkLine.FlightNo,
                eta = param.TrunkLine.Eta,
                etd = param.TrunkLine.Etd,
                fromPortCode = param.TrunkLine.FromPortCode,
                transitPortCode = param.TrunkLine.TransitPortCode,
                toPortCode = param.TrunkLine.ToPortCode,
            };
            transportRequest.bigBagList = param.Box.Select(x => x.UserBoxNumber).ToList();
            transportRequest.shipmentWeight = Convert.ToDouble(param.TrunkLine.TotalWeight);
            if (!string.IsNullOrEmpty(param.TrunkLine.PdfUrl))
            {
                WebClient webClient = new WebClient();
                var data = webClient.DownloadData(param.TrunkLine.PdfUrl);
                transportRequest.mawbFiles = new List<string>() { Convert.ToBase64String(data) }; //new List<MawbFiles>() { new MawbFiles() { mawbFile = Convert.ToBase64String(data) } };
            }
            transportRequest.cargoType = param.TrunkLine.CargoType.GetName();
            transportRequest.uldNo = param.TrunkLine.UldNo;
            transportRequest.uldType = param.TrunkLine.UldType;
            return transportRequest;
        }

    }
}
