using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Mapster.Models;
using NetinaShop.Domain.Dtos.LargDtos;
using NetinaShop.Domain.Dtos.SmallDtos;
using NetinaShop.Domain.Entities.Accounting;
using NetinaShop.Domain.Entities.Orders;
using NetinaShop.Domain.Entities.Products;
using NetinaShop.Domain.Entities.Users;
using NetinaShop.Domain.Entities.Warehouses;

namespace NetinaShop.Domain.Mappers
{
    public static partial class OrderMapper
    {
        public static Order AdaptToOrder(this OrderLDto p1)
        {
            return p1 == null ? null : new Order()
            {
                FactorCode = p1.FactorCode,
                TotalProductsPrice = (double)p1.TotalProductsPrice,
                PackingPrice = (double)p1.PackingPrice,
                ServicePrice = (double)p1.ServicePrice,
                DeliveryPrice = (double)p1.DeliveryPrice,
                DiscountPrice = (double)p1.DiscountPrice,
                DiscountCodePrice = p1.DiscountCodePrice,
                ProductDiscountPrice = p1.ProductDiscountPrice,
                TaxesPrice = (double)p1.TaxesPrice,
                TotalPrice = (double)p1.TotalPrice,
                IsPayed = p1.IsPayed,
                OrderStatus = p1.OrderStatus,
                DoneAt = p1.DoneAt,
                OrderAt = p1.OrderAt,
                PreparingMinute = p1.PreparingMinute,
                DiscountCode = p1.DiscountCode,
                User = new ApplicationUser() {PhoneNumber = p1.UserPhoneNumber},
                OrderDelivery = p1.OrderDelivery == null ? null : new OrderDelivery()
                {
                    AddressId = p1.OrderDelivery.AddressId,
                    Address = p1.OrderDelivery.Address == null ? null : (UserAddress)Convert.ChangeType((object)p1.OrderDelivery.Address, typeof(UserAddress)),
                    DeliveryCost = p1.OrderDelivery.DeliveryCost,
                    ShippingId = p1.OrderDelivery.ShippingId,
                    Shipping = new Shipping() {Id = p1.OrderDelivery.ShippingId},
                    OrderId = p1.OrderDelivery.OrderId,
                    Order = new Order() {Id = p1.OrderDelivery.OrderId},
                    Id = p1.OrderDelivery.Id,
                    CreatedAt = p1.OrderDelivery.CreatedAt
                },
                OrderProducts = funcMain1(p1.OrderProducts),
                Payments = funcMain2(p1.Payments),
                Id = p1.Id,
                CreatedAt = p1.CreatedAt
            };
        }
        public static Order AdaptTo(this OrderLDto p4, Order p5)
        {
            if (p4 == null)
            {
                return null;
            }
            Order result = p5 ?? new Order();
            
            result.FactorCode = p4.FactorCode;
            result.TotalProductsPrice = (double)p4.TotalProductsPrice;
            result.PackingPrice = (double)p4.PackingPrice;
            result.ServicePrice = (double)p4.ServicePrice;
            result.DeliveryPrice = (double)p4.DeliveryPrice;
            result.DiscountPrice = (double)p4.DiscountPrice;
            result.DiscountCodePrice = p4.DiscountCodePrice;
            result.ProductDiscountPrice = p4.ProductDiscountPrice;
            result.TaxesPrice = (double)p4.TaxesPrice;
            result.TotalPrice = (double)p4.TotalPrice;
            result.IsPayed = p4.IsPayed;
            result.OrderStatus = p4.OrderStatus;
            result.DoneAt = p4.DoneAt;
            result.OrderAt = p4.OrderAt;
            result.PreparingMinute = p4.PreparingMinute;
            result.DiscountCode = p4.DiscountCode;
            result.User = funcMain3(new Never(), result.User, p4);
            result.OrderDelivery = funcMain4(p4.OrderDelivery, result.OrderDelivery);
            result.OrderProducts = funcMain7(p4.OrderProducts, result.OrderProducts);
            result.Payments = funcMain8(p4.Payments, result.Payments);
            result.Id = p4.Id;
            result.CreatedAt = p4.CreatedAt;
            return result;
            
        }
        public static Expression<Func<OrderLDto, Order>> ProjectToOrder => p18 => new Order()
        {
            FactorCode = p18.FactorCode,
            TotalProductsPrice = (double)p18.TotalProductsPrice,
            PackingPrice = (double)p18.PackingPrice,
            ServicePrice = (double)p18.ServicePrice,
            DeliveryPrice = (double)p18.DeliveryPrice,
            DiscountPrice = (double)p18.DiscountPrice,
            DiscountCodePrice = p18.DiscountCodePrice,
            ProductDiscountPrice = p18.ProductDiscountPrice,
            TaxesPrice = (double)p18.TaxesPrice,
            TotalPrice = (double)p18.TotalPrice,
            IsPayed = p18.IsPayed,
            OrderStatus = p18.OrderStatus,
            DoneAt = p18.DoneAt,
            OrderAt = p18.OrderAt,
            PreparingMinute = p18.PreparingMinute,
            DiscountCode = p18.DiscountCode,
            User = new ApplicationUser() {PhoneNumber = p18.UserPhoneNumber},
            OrderDelivery = p18.OrderDelivery == null ? null : new OrderDelivery()
            {
                AddressId = p18.OrderDelivery.AddressId,
                Address = p18.OrderDelivery.Address == null ? null : (UserAddress)Convert.ChangeType((object)p18.OrderDelivery.Address, typeof(UserAddress)),
                DeliveryCost = p18.OrderDelivery.DeliveryCost,
                ShippingId = p18.OrderDelivery.ShippingId,
                Shipping = new Shipping() {Id = p18.OrderDelivery.ShippingId},
                OrderId = p18.OrderDelivery.OrderId,
                Order = new Order() {Id = p18.OrderDelivery.OrderId},
                Id = p18.OrderDelivery.Id,
                CreatedAt = p18.OrderDelivery.CreatedAt
            },
            OrderProducts = p18.OrderProducts.Select<OrderProductSDto, OrderProduct>(p19 => new OrderProduct()
            {
                Count = p19.Count,
                ProductFee = p19.ProductFee,
                ProductFeeWithDiscount = p19.ProductFeeWithDiscount,
                HasDiscount = p19.HasDiscount,
                ProductCost = p19.ProductCost,
                PackingFee = p19.PackingFee,
                PackingCost = p19.PackingCost,
                OrderProductStatus = p19.OrderProductStatus,
                ProductId = p19.ProductId,
                Product = new Product()
                {
                    Cost = p19.ProductCost,
                    Id = p19.ProductId
                },
                OrderId = p19.OrderId,
                Order = new Order() {Id = p19.OrderId},
                Id = p19.Id,
                CreatedAt = p19.CreatedAt
            }).ToList<OrderProduct>(),
            Payments = p18.Payments.Select<PaymentSDto, Payment>(p20 => new Payment()
            {
                FactorNumber = p20.FactorNumber,
                Amount = p20.Amount,
                Description = p20.Description,
                TransactionCode = p20.TransactionCode,
                CardPan = p20.CardPan,
                Authority = p20.Authority,
                Type = p20.Type,
                Status = p20.Status,
                OrderId = p20.OrderId,
                Order = new Order() {Id = p20.OrderId},
                UserId = p20.UserId,
                User = new ApplicationUser()
                {
                    Id = p20.UserId,
                    PhoneNumber = p20.UserPhoneNumber
                },
                Id = p20.Id,
                CreatedAt = p20.CreatedAt
            }).ToList<Payment>(),
            Id = p18.Id,
            CreatedAt = p18.CreatedAt
        };
        public static OrderLDto AdaptToLDto(this Order p21)
        {
            return p21 == null ? null : new OrderLDto()
            {
                FactorCode = p21.FactorCode,
                TotalPrice = (long)p21.TotalPrice,
                DeliveryPrice = (long)p21.DeliveryPrice,
                TaxesPrice = (long)p21.TaxesPrice,
                ServicePrice = (long)p21.ServicePrice,
                PackingPrice = (long)p21.PackingPrice,
                TotalProductsPrice = (long)p21.TotalProductsPrice,
                DiscountCodePrice = p21.DiscountCodePrice,
                ProductDiscountPrice = p21.ProductDiscountPrice,
                DiscountPrice = (long)p21.DiscountPrice,
                IsPayed = p21.IsPayed,
                OrderStatus = p21.OrderStatus,
                DoneAt = p21.DoneAt,
                OrderAt = p21.OrderAt,
                PreparingMinute = p21.PreparingMinute,
                DiscountCode = p21.DiscountCode,
                UserFullName = p21.User != null ? p21.User.FirstName + " " + p21.User.LastName : string.Empty,
                UserPhoneNumber = p21.User != null ? p21.User.PhoneNumber : string.Empty,
                OrderProducts = funcMain9(p21.OrderProducts),
                Payments = funcMain10(p21.Payments),
                OrderDelivery = p21.OrderDelivery == null ? null : new OrderDeliverySDto()
                {
                    Address = p21.OrderDelivery.Address == null ? null : p21.OrderDelivery.Address.ToString(),
                    ShippingMethod = p21.OrderDelivery.Shipping != null ? p21.OrderDelivery.Shipping.Name : string.Empty,
                    DeliveryCost = p21.OrderDelivery.DeliveryCost,
                    AddressId = p21.OrderDelivery.AddressId,
                    OrderId = p21.OrderDelivery.OrderId,
                    ShippingId = p21.OrderDelivery.ShippingId,
                    Id = p21.OrderDelivery.Id,
                    CreatedAt = p21.OrderDelivery.CreatedAt
                },
                Id = p21.Id,
                CreatedAt = p21.CreatedAt
            };
        }
        public static OrderLDto AdaptTo(this Order p24, OrderLDto p25)
        {
            if (p24 == null)
            {
                return null;
            }
            OrderLDto result = p25 ?? new OrderLDto();
            
            result.FactorCode = p24.FactorCode;
            result.TotalPrice = (long)p24.TotalPrice;
            result.DeliveryPrice = (long)p24.DeliveryPrice;
            result.TaxesPrice = (long)p24.TaxesPrice;
            result.ServicePrice = (long)p24.ServicePrice;
            result.PackingPrice = (long)p24.PackingPrice;
            result.TotalProductsPrice = (long)p24.TotalProductsPrice;
            result.DiscountCodePrice = p24.DiscountCodePrice;
            result.ProductDiscountPrice = p24.ProductDiscountPrice;
            result.DiscountPrice = (long)p24.DiscountPrice;
            result.IsPayed = p24.IsPayed;
            result.OrderStatus = p24.OrderStatus;
            result.DoneAt = p24.DoneAt;
            result.OrderAt = p24.OrderAt;
            result.PreparingMinute = p24.PreparingMinute;
            result.DiscountCode = p24.DiscountCode;
            result.UserFullName = p24.User != null ? p24.User.FirstName + " " + p24.User.LastName : string.Empty;
            result.UserPhoneNumber = p24.User != null ? p24.User.PhoneNumber : string.Empty;
            result.OrderProducts = funcMain11(p24.OrderProducts, result.OrderProducts);
            result.Payments = funcMain12(p24.Payments, result.Payments);
            result.OrderDelivery = funcMain13(p24.OrderDelivery, result.OrderDelivery);
            result.Id = p24.Id;
            result.CreatedAt = p24.CreatedAt;
            return result;
            
        }
        public static Expression<Func<Order, OrderLDto>> ProjectToLDto => p32 => new OrderLDto()
        {
            FactorCode = p32.FactorCode,
            TotalPrice = (long)p32.TotalPrice,
            DeliveryPrice = (long)p32.DeliveryPrice,
            TaxesPrice = (long)p32.TaxesPrice,
            ServicePrice = (long)p32.ServicePrice,
            PackingPrice = (long)p32.PackingPrice,
            TotalProductsPrice = (long)p32.TotalProductsPrice,
            DiscountCodePrice = p32.DiscountCodePrice,
            ProductDiscountPrice = p32.ProductDiscountPrice,
            DiscountPrice = (long)p32.DiscountPrice,
            IsPayed = p32.IsPayed,
            OrderStatus = p32.OrderStatus,
            DoneAt = p32.DoneAt,
            OrderAt = p32.OrderAt,
            PreparingMinute = p32.PreparingMinute,
            DiscountCode = p32.DiscountCode,
            UserFullName = p32.User != null ? p32.User.FirstName + " " + p32.User.LastName : string.Empty,
            UserPhoneNumber = p32.User != null ? p32.User.PhoneNumber : string.Empty,
            OrderProducts = p32.OrderProducts.Select<OrderProduct, OrderProductSDto>(p33 => new OrderProductSDto()
            {
                Count = p33.Count,
                ProductFee = p33.ProductFee,
                ProductFeeWithDiscount = p33.ProductFeeWithDiscount,
                HasDiscount = p33.HasDiscount,
                ProductCost = p33.ProductCost,
                PackingFee = p33.PackingFee,
                PackingCost = p33.PackingCost,
                OrderProductStatus = p33.OrderProductStatus,
                ProductId = p33.ProductId,
                ProductName = p33.Product != null ? p33.Product.PersianName : string.Empty,
                OrderId = p33.OrderId,
                Id = p33.Id,
                CreatedAt = p33.CreatedAt
            }).ToList<OrderProductSDto>(),
            Payments = p32.Payments.Select<Payment, PaymentSDto>(p34 => new PaymentSDto()
            {
                FactorNumber = p34.FactorNumber,
                Amount = p34.Amount,
                Description = p34.Description,
                TransactionCode = p34.TransactionCode,
                CardPan = p34.CardPan,
                Authority = p34.Authority,
                Type = p34.Type,
                Status = p34.Status,
                OrderId = p34.OrderId,
                UserId = p34.UserId,
                UserFullName = p34.User != null ? p34.User.FirstName + " " + p34.User.LastName : string.Empty,
                UserPhoneNumber = p34.User != null ? p34.User.PhoneNumber : string.Empty,
                Id = p34.Id,
                CreatedAt = p34.CreatedAt
            }).ToList<PaymentSDto>(),
            OrderDelivery = p32.OrderDelivery == null ? null : new OrderDeliverySDto()
            {
                Address = p32.OrderDelivery.Address == null ? null : p32.OrderDelivery.Address.ToString(),
                ShippingMethod = p32.OrderDelivery.Shipping != null ? p32.OrderDelivery.Shipping.Name : string.Empty,
                DeliveryCost = p32.OrderDelivery.DeliveryCost,
                AddressId = p32.OrderDelivery.AddressId,
                OrderId = p32.OrderDelivery.OrderId,
                ShippingId = p32.OrderDelivery.ShippingId,
                Id = p32.OrderDelivery.Id,
                CreatedAt = p32.OrderDelivery.CreatedAt
            },
            Id = p32.Id,
            CreatedAt = p32.CreatedAt
        };
        public static Order AdaptToOrder(this OrderSDto p35)
        {
            return p35 == null ? null : new Order()
            {
                FactorCode = p35.FactorCode,
                TotalProductsPrice = p35.TotalProductsPrice,
                PackingPrice = p35.PackingPrice,
                ServicePrice = p35.ServicePrice,
                DeliveryPrice = p35.DeliveryPrice,
                DiscountPrice = p35.DiscountPrice,
                DiscountCodePrice = p35.DiscountCodePrice,
                ProductDiscountPrice = p35.ProductDiscountPrice,
                TaxesPrice = p35.TaxesPrice,
                TotalPrice = p35.TotalPrice,
                IsPayed = p35.IsPayed,
                PayedAt = p35.PayedAt,
                OrderStatus = p35.OrderStatus,
                DoneAt = p35.DoneAt,
                OrderAt = p35.OrderAt,
                PreparingMinute = p35.PreparingMinute,
                DiscountCode = p35.DiscountCode,
                UserId = p35.UserId,
                User = new ApplicationUser()
                {
                    Id = p35.UserId,
                    PhoneNumber = p35.UserPhoneNumber
                },
                Id = p35.Id,
                CreatedAt = p35.CreatedAt
            };
        }
        public static Order AdaptTo(this OrderSDto p36, Order p37)
        {
            if (p36 == null)
            {
                return null;
            }
            Order result = p37 ?? new Order();
            
            result.FactorCode = p36.FactorCode;
            result.TotalProductsPrice = p36.TotalProductsPrice;
            result.PackingPrice = p36.PackingPrice;
            result.ServicePrice = p36.ServicePrice;
            result.DeliveryPrice = p36.DeliveryPrice;
            result.DiscountPrice = p36.DiscountPrice;
            result.DiscountCodePrice = p36.DiscountCodePrice;
            result.ProductDiscountPrice = p36.ProductDiscountPrice;
            result.TaxesPrice = p36.TaxesPrice;
            result.TotalPrice = p36.TotalPrice;
            result.IsPayed = p36.IsPayed;
            result.PayedAt = p36.PayedAt;
            result.OrderStatus = p36.OrderStatus;
            result.DoneAt = p36.DoneAt;
            result.OrderAt = p36.OrderAt;
            result.PreparingMinute = p36.PreparingMinute;
            result.DiscountCode = p36.DiscountCode;
            result.UserId = p36.UserId;
            result.User = funcMain14(new Never(), result.User, p36);
            result.Id = p36.Id;
            result.CreatedAt = p36.CreatedAt;
            return result;
            
        }
        public static OrderSDto AdaptToSDto(this Order p40)
        {
            return p40 == null ? null : new OrderSDto()
            {
                TotalPrice = p40.TotalPrice,
                FactorCode = p40.FactorCode,
                DeliveryPrice = p40.DeliveryPrice,
                TaxesPrice = p40.TaxesPrice,
                ServicePrice = p40.ServicePrice,
                PackingPrice = p40.PackingPrice,
                TotalProductsPrice = p40.TotalProductsPrice,
                DiscountPrice = p40.DiscountPrice,
                DiscountCodePrice = p40.DiscountCodePrice,
                ProductDiscountPrice = p40.ProductDiscountPrice,
                IsPayed = p40.IsPayed,
                OrderStatus = p40.OrderStatus,
                PayedAt = p40.PayedAt,
                DoneAt = p40.DoneAt,
                OrderAt = p40.OrderAt,
                PreparingMinute = p40.PreparingMinute,
                DiscountCode = p40.DiscountCode,
                UserFullName = p40.User != null ? p40.User.FirstName + " " + p40.User.LastName : string.Empty,
                UserPhoneNumber = p40.User != null ? p40.User.PhoneNumber : string.Empty,
                UserId = p40.UserId,
                Id = p40.Id,
                CreatedAt = p40.CreatedAt
            };
        }
        public static OrderSDto AdaptTo(this Order p41, OrderSDto p42)
        {
            if (p41 == null)
            {
                return null;
            }
            OrderSDto result = p42 ?? new OrderSDto();
            
            result.TotalPrice = p41.TotalPrice;
            result.FactorCode = p41.FactorCode;
            result.DeliveryPrice = p41.DeliveryPrice;
            result.TaxesPrice = p41.TaxesPrice;
            result.ServicePrice = p41.ServicePrice;
            result.PackingPrice = p41.PackingPrice;
            result.TotalProductsPrice = p41.TotalProductsPrice;
            result.DiscountPrice = p41.DiscountPrice;
            result.DiscountCodePrice = p41.DiscountCodePrice;
            result.ProductDiscountPrice = p41.ProductDiscountPrice;
            result.IsPayed = p41.IsPayed;
            result.OrderStatus = p41.OrderStatus;
            result.PayedAt = p41.PayedAt;
            result.DoneAt = p41.DoneAt;
            result.OrderAt = p41.OrderAt;
            result.PreparingMinute = p41.PreparingMinute;
            result.DiscountCode = p41.DiscountCode;
            result.UserFullName = p41.User != null ? p41.User.FirstName + " " + p41.User.LastName : string.Empty;
            result.UserPhoneNumber = p41.User != null ? p41.User.PhoneNumber : string.Empty;
            result.UserId = p41.UserId;
            result.Id = p41.Id;
            result.CreatedAt = p41.CreatedAt;
            return result;
            
        }
        public static Expression<Func<Order, OrderSDto>> ProjectToSDto => p43 => new OrderSDto()
        {
            TotalPrice = p43.TotalPrice,
            FactorCode = p43.FactorCode,
            DeliveryPrice = p43.DeliveryPrice,
            TaxesPrice = p43.TaxesPrice,
            ServicePrice = p43.ServicePrice,
            PackingPrice = p43.PackingPrice,
            TotalProductsPrice = p43.TotalProductsPrice,
            DiscountPrice = p43.DiscountPrice,
            DiscountCodePrice = p43.DiscountCodePrice,
            ProductDiscountPrice = p43.ProductDiscountPrice,
            IsPayed = p43.IsPayed,
            OrderStatus = p43.OrderStatus,
            PayedAt = p43.PayedAt,
            DoneAt = p43.DoneAt,
            OrderAt = p43.OrderAt,
            PreparingMinute = p43.PreparingMinute,
            DiscountCode = p43.DiscountCode,
            UserFullName = p43.User != null ? p43.User.FirstName + " " + p43.User.LastName : string.Empty,
            UserPhoneNumber = p43.User != null ? p43.User.PhoneNumber : string.Empty,
            UserId = p43.UserId,
            Id = p43.Id,
            CreatedAt = p43.CreatedAt
        };
        
        private static List<OrderProduct> funcMain1(List<OrderProductSDto> p2)
        {
            if (p2 == null)
            {
                return null;
            }
            List<OrderProduct> result = new List<OrderProduct>(p2.Count);
            
            int i = 0;
            int len = p2.Count;
            
            while (i < len)
            {
                OrderProductSDto item = p2[i];
                result.Add(item == null ? null : new OrderProduct()
                {
                    Count = item.Count,
                    ProductFee = item.ProductFee,
                    ProductFeeWithDiscount = item.ProductFeeWithDiscount,
                    HasDiscount = item.HasDiscount,
                    ProductCost = item.ProductCost,
                    PackingFee = item.PackingFee,
                    PackingCost = item.PackingCost,
                    OrderProductStatus = item.OrderProductStatus,
                    ProductId = item.ProductId,
                    Product = new Product()
                    {
                        Cost = item.ProductCost,
                        Id = item.ProductId
                    },
                    OrderId = item.OrderId,
                    Order = new Order() {Id = item.OrderId},
                    Id = item.Id,
                    CreatedAt = item.CreatedAt
                });
                i++;
            }
            return result;
            
        }
        
        private static List<Payment> funcMain2(List<PaymentSDto> p3)
        {
            if (p3 == null)
            {
                return null;
            }
            List<Payment> result = new List<Payment>(p3.Count);
            
            int i = 0;
            int len = p3.Count;
            
            while (i < len)
            {
                PaymentSDto item = p3[i];
                result.Add(item == null ? null : new Payment()
                {
                    FactorNumber = item.FactorNumber,
                    Amount = item.Amount,
                    Description = item.Description,
                    TransactionCode = item.TransactionCode,
                    CardPan = item.CardPan,
                    Authority = item.Authority,
                    Type = item.Type,
                    Status = item.Status,
                    OrderId = item.OrderId,
                    Order = new Order() {Id = item.OrderId},
                    UserId = item.UserId,
                    User = new ApplicationUser()
                    {
                        Id = item.UserId,
                        PhoneNumber = item.UserPhoneNumber
                    },
                    Id = item.Id,
                    CreatedAt = item.CreatedAt
                });
                i++;
            }
            return result;
            
        }
        
        private static ApplicationUser funcMain3(Never p6, ApplicationUser p7, OrderLDto p4)
        {
            ApplicationUser result = p7 ?? new ApplicationUser();
            
            result.PhoneNumber = p4.UserPhoneNumber;
            return result;
            
        }
        
        private static OrderDelivery funcMain4(OrderDeliverySDto p8, OrderDelivery p9)
        {
            if (p8 == null)
            {
                return null;
            }
            OrderDelivery result = p9 ?? new OrderDelivery();
            
            result.AddressId = p8.AddressId;
            result.Address = p8.Address == null ? null : (UserAddress)Convert.ChangeType((object)p8.Address, typeof(UserAddress));
            result.DeliveryCost = p8.DeliveryCost;
            result.ShippingId = p8.ShippingId;
            result.Shipping = funcMain5(new Never(), result.Shipping, p8);
            result.OrderId = p8.OrderId;
            result.Order = funcMain6(new Never(), result.Order, p8);
            result.Id = p8.Id;
            result.CreatedAt = p8.CreatedAt;
            return result;
            
        }
        
        private static List<OrderProduct> funcMain7(List<OrderProductSDto> p14, List<OrderProduct> p15)
        {
            if (p14 == null)
            {
                return null;
            }
            List<OrderProduct> result = new List<OrderProduct>(p14.Count);
            
            int i = 0;
            int len = p14.Count;
            
            while (i < len)
            {
                OrderProductSDto item = p14[i];
                result.Add(item == null ? null : new OrderProduct()
                {
                    Count = item.Count,
                    ProductFee = item.ProductFee,
                    ProductFeeWithDiscount = item.ProductFeeWithDiscount,
                    HasDiscount = item.HasDiscount,
                    ProductCost = item.ProductCost,
                    PackingFee = item.PackingFee,
                    PackingCost = item.PackingCost,
                    OrderProductStatus = item.OrderProductStatus,
                    ProductId = item.ProductId,
                    Product = new Product()
                    {
                        Cost = item.ProductCost,
                        Id = item.ProductId
                    },
                    OrderId = item.OrderId,
                    Order = new Order() {Id = item.OrderId},
                    Id = item.Id,
                    CreatedAt = item.CreatedAt
                });
                i++;
            }
            return result;
            
        }
        
        private static List<Payment> funcMain8(List<PaymentSDto> p16, List<Payment> p17)
        {
            if (p16 == null)
            {
                return null;
            }
            List<Payment> result = new List<Payment>(p16.Count);
            
            int i = 0;
            int len = p16.Count;
            
            while (i < len)
            {
                PaymentSDto item = p16[i];
                result.Add(item == null ? null : new Payment()
                {
                    FactorNumber = item.FactorNumber,
                    Amount = item.Amount,
                    Description = item.Description,
                    TransactionCode = item.TransactionCode,
                    CardPan = item.CardPan,
                    Authority = item.Authority,
                    Type = item.Type,
                    Status = item.Status,
                    OrderId = item.OrderId,
                    Order = new Order() {Id = item.OrderId},
                    UserId = item.UserId,
                    User = new ApplicationUser()
                    {
                        Id = item.UserId,
                        PhoneNumber = item.UserPhoneNumber
                    },
                    Id = item.Id,
                    CreatedAt = item.CreatedAt
                });
                i++;
            }
            return result;
            
        }
        
        private static List<OrderProductSDto> funcMain9(List<OrderProduct> p22)
        {
            if (p22 == null)
            {
                return null;
            }
            List<OrderProductSDto> result = new List<OrderProductSDto>(p22.Count);
            
            int i = 0;
            int len = p22.Count;
            
            while (i < len)
            {
                OrderProduct item = p22[i];
                result.Add(item == null ? null : new OrderProductSDto()
                {
                    Count = item.Count,
                    ProductFee = item.ProductFee,
                    ProductFeeWithDiscount = item.ProductFeeWithDiscount,
                    HasDiscount = item.HasDiscount,
                    ProductCost = item.ProductCost,
                    PackingFee = item.PackingFee,
                    PackingCost = item.PackingCost,
                    OrderProductStatus = item.OrderProductStatus,
                    ProductId = item.ProductId,
                    ProductName = item.Product != null ? item.Product.PersianName : string.Empty,
                    OrderId = item.OrderId,
                    Id = item.Id,
                    CreatedAt = item.CreatedAt
                });
                i++;
            }
            return result;
            
        }
        
        private static List<PaymentSDto> funcMain10(List<Payment> p23)
        {
            if (p23 == null)
            {
                return null;
            }
            List<PaymentSDto> result = new List<PaymentSDto>(p23.Count);
            
            int i = 0;
            int len = p23.Count;
            
            while (i < len)
            {
                Payment item = p23[i];
                result.Add(item == null ? null : new PaymentSDto()
                {
                    FactorNumber = item.FactorNumber,
                    Amount = item.Amount,
                    Description = item.Description,
                    TransactionCode = item.TransactionCode,
                    CardPan = item.CardPan,
                    Authority = item.Authority,
                    Type = item.Type,
                    Status = item.Status,
                    OrderId = item.OrderId,
                    UserId = item.UserId,
                    UserFullName = item.User != null ? item.User.FirstName + " " + item.User.LastName : string.Empty,
                    UserPhoneNumber = item.User != null ? item.User.PhoneNumber : string.Empty,
                    Id = item.Id,
                    CreatedAt = item.CreatedAt
                });
                i++;
            }
            return result;
            
        }
        
        private static List<OrderProductSDto> funcMain11(List<OrderProduct> p26, List<OrderProductSDto> p27)
        {
            if (p26 == null)
            {
                return null;
            }
            List<OrderProductSDto> result = new List<OrderProductSDto>(p26.Count);
            
            int i = 0;
            int len = p26.Count;
            
            while (i < len)
            {
                OrderProduct item = p26[i];
                result.Add(item == null ? null : new OrderProductSDto()
                {
                    Count = item.Count,
                    ProductFee = item.ProductFee,
                    ProductFeeWithDiscount = item.ProductFeeWithDiscount,
                    HasDiscount = item.HasDiscount,
                    ProductCost = item.ProductCost,
                    PackingFee = item.PackingFee,
                    PackingCost = item.PackingCost,
                    OrderProductStatus = item.OrderProductStatus,
                    ProductId = item.ProductId,
                    ProductName = item.Product != null ? item.Product.PersianName : string.Empty,
                    OrderId = item.OrderId,
                    Id = item.Id,
                    CreatedAt = item.CreatedAt
                });
                i++;
            }
            return result;
            
        }
        
        private static List<PaymentSDto> funcMain12(List<Payment> p28, List<PaymentSDto> p29)
        {
            if (p28 == null)
            {
                return null;
            }
            List<PaymentSDto> result = new List<PaymentSDto>(p28.Count);
            
            int i = 0;
            int len = p28.Count;
            
            while (i < len)
            {
                Payment item = p28[i];
                result.Add(item == null ? null : new PaymentSDto()
                {
                    FactorNumber = item.FactorNumber,
                    Amount = item.Amount,
                    Description = item.Description,
                    TransactionCode = item.TransactionCode,
                    CardPan = item.CardPan,
                    Authority = item.Authority,
                    Type = item.Type,
                    Status = item.Status,
                    OrderId = item.OrderId,
                    UserId = item.UserId,
                    UserFullName = item.User != null ? item.User.FirstName + " " + item.User.LastName : string.Empty,
                    UserPhoneNumber = item.User != null ? item.User.PhoneNumber : string.Empty,
                    Id = item.Id,
                    CreatedAt = item.CreatedAt
                });
                i++;
            }
            return result;
            
        }
        
        private static OrderDeliverySDto funcMain13(OrderDelivery p30, OrderDeliverySDto p31)
        {
            if (p30 == null)
            {
                return null;
            }
            OrderDeliverySDto result = p31 ?? new OrderDeliverySDto();
            
            result.Address = p30.Address == null ? null : p30.Address.ToString();
            result.ShippingMethod = p30.Shipping != null ? p30.Shipping.Name : string.Empty;
            result.DeliveryCost = p30.DeliveryCost;
            result.AddressId = p30.AddressId;
            result.OrderId = p30.OrderId;
            result.ShippingId = p30.ShippingId;
            result.Id = p30.Id;
            result.CreatedAt = p30.CreatedAt;
            return result;
            
        }
        
        private static ApplicationUser funcMain14(Never p38, ApplicationUser p39, OrderSDto p36)
        {
            ApplicationUser result = p39 ?? new ApplicationUser();
            
            result.Id = p36.UserId;
            result.PhoneNumber = p36.UserPhoneNumber;
            return result;
            
        }
        
        private static Shipping funcMain5(Never p10, Shipping p11, OrderDeliverySDto p8)
        {
            Shipping result = p11 ?? new Shipping();
            
            result.Id = p8.ShippingId;
            return result;
            
        }
        
        private static Order funcMain6(Never p12, Order p13, OrderDeliverySDto p8)
        {
            Order result = p13 ?? new Order();
            
            result.Id = p8.OrderId;
            return result;
            
        }
    }
}