using System;
using System.Linq.Expressions;
using Mapster.Models;
using NetinaShop.Domain.Dtos.SmallDtos;
using NetinaShop.Domain.Entities.Orders;
using NetinaShop.Domain.Entities.Products;

namespace NetinaShop.Domain.Mappers
{
    public static partial class OrderProductMapper
    {
        public static OrderProduct AdaptToOrderProduct(this OrderProductSDto p1)
        {
            return p1 == null ? null : new OrderProduct()
            {
                Count = p1.Count,
                ProductFee = p1.ProductFee,
                ProductFeeWithDiscount = p1.ProductFeeWithDiscount,
                HasDiscount = p1.HasDiscount,
                ProductCost = p1.ProductCost,
                PackingFee = p1.PackingFee,
                PackingCost = p1.PackingCost,
                OrderProductStatus = p1.OrderProductStatus,
                ProductId = p1.ProductId,
                Product = new Product()
                {
                    Cost = p1.ProductCost,
                    Id = p1.ProductId
                },
                OrderId = p1.OrderId,
                Order = new Order() {Id = p1.OrderId},
                Id = p1.Id,
                CreatedAt = p1.CreatedAt
            };
        }
        public static OrderProduct AdaptTo(this OrderProductSDto p2, OrderProduct p3)
        {
            if (p2 == null)
            {
                return null;
            }
            OrderProduct result = p3 ?? new OrderProduct();
            
            result.Count = p2.Count;
            result.ProductFee = p2.ProductFee;
            result.ProductFeeWithDiscount = p2.ProductFeeWithDiscount;
            result.HasDiscount = p2.HasDiscount;
            result.ProductCost = p2.ProductCost;
            result.PackingFee = p2.PackingFee;
            result.PackingCost = p2.PackingCost;
            result.OrderProductStatus = p2.OrderProductStatus;
            result.ProductId = p2.ProductId;
            result.Product = funcMain1(new Never(), result.Product, p2);
            result.OrderId = p2.OrderId;
            result.Order = funcMain2(new Never(), result.Order, p2);
            result.Id = p2.Id;
            result.CreatedAt = p2.CreatedAt;
            return result;
            
        }
        public static OrderProductSDto AdaptToSDto(this OrderProduct p8)
        {
            return p8 == null ? null : new OrderProductSDto()
            {
                Count = p8.Count,
                ProductFee = p8.ProductFee,
                ProductFeeWithDiscount = p8.ProductFeeWithDiscount,
                HasDiscount = p8.HasDiscount,
                ProductCost = p8.ProductCost,
                PackingFee = p8.PackingFee,
                PackingCost = p8.PackingCost,
                OrderProductStatus = p8.OrderProductStatus,
                ProductId = p8.ProductId,
                ProductName = p8.Product != null ? p8.Product.PersianName : string.Empty,
                OrderId = p8.OrderId,
                Id = p8.Id,
                CreatedAt = p8.CreatedAt
            };
        }
        public static OrderProductSDto AdaptTo(this OrderProduct p9, OrderProductSDto p10)
        {
            if (p9 == null)
            {
                return null;
            }
            OrderProductSDto result = p10 ?? new OrderProductSDto();
            
            result.Count = p9.Count;
            result.ProductFee = p9.ProductFee;
            result.ProductFeeWithDiscount = p9.ProductFeeWithDiscount;
            result.HasDiscount = p9.HasDiscount;
            result.ProductCost = p9.ProductCost;
            result.PackingFee = p9.PackingFee;
            result.PackingCost = p9.PackingCost;
            result.OrderProductStatus = p9.OrderProductStatus;
            result.ProductId = p9.ProductId;
            result.ProductName = p9.Product != null ? p9.Product.PersianName : string.Empty;
            result.OrderId = p9.OrderId;
            result.Id = p9.Id;
            result.CreatedAt = p9.CreatedAt;
            return result;
            
        }
        public static Expression<Func<OrderProduct, OrderProductSDto>> ProjectToSDto => p11 => new OrderProductSDto()
        {
            Count = p11.Count,
            ProductFee = p11.ProductFee,
            ProductFeeWithDiscount = p11.ProductFeeWithDiscount,
            HasDiscount = p11.HasDiscount,
            ProductCost = p11.ProductCost,
            PackingFee = p11.PackingFee,
            PackingCost = p11.PackingCost,
            OrderProductStatus = p11.OrderProductStatus,
            ProductId = p11.ProductId,
            ProductName = p11.Product != null ? p11.Product.PersianName : string.Empty,
            OrderId = p11.OrderId,
            Id = p11.Id,
            CreatedAt = p11.CreatedAt
        };
        
        private static Product funcMain1(Never p4, Product p5, OrderProductSDto p2)
        {
            Product result = p5 ?? new Product();
            
            result.Cost = p2.ProductCost;
            result.Id = p2.ProductId;
            return result;
            
        }
        
        private static Order funcMain2(Never p6, Order p7, OrderProductSDto p2)
        {
            Order result = p7 ?? new Order();
            
            result.Id = p2.OrderId;
            return result;
            
        }
    }
}