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

namespace NetinaShop.Domain.Mappers
{
    public static partial class PaymentMapper
    {
        public static Payment AdaptToPayment(this PaymentSDto p1)
        {
            return p1 == null ? null : new Payment()
            {
                FactorNumber = p1.FactorNumber,
                Amount = p1.Amount,
                Description = p1.Description,
                TransactionCode = p1.TransactionCode,
                CardPan = p1.CardPan,
                Authority = p1.Authority,
                Type = p1.Type,
                Status = p1.Status,
                OrderId = p1.OrderId,
                Order = new Order() {Id = p1.OrderId},
                Id = p1.Id,
                CreatedAt = p1.CreatedAt
            };
        }
        public static Payment AdaptTo(this PaymentSDto p2, Payment p3)
        {
            if (p2 == null)
            {
                return null;
            }
            Payment result = p3 ?? new Payment();
            
            result.FactorNumber = p2.FactorNumber;
            result.Amount = p2.Amount;
            result.Description = p2.Description;
            result.TransactionCode = p2.TransactionCode;
            result.CardPan = p2.CardPan;
            result.Authority = p2.Authority;
            result.Type = p2.Type;
            result.Status = p2.Status;
            result.OrderId = p2.OrderId;
            result.Order = funcMain1(new Never(), result.Order, p2);
            result.Id = p2.Id;
            result.CreatedAt = p2.CreatedAt;
            return result;
            
        }
        public static PaymentSDto AdaptToSDto(this Payment p6)
        {
            return p6 == null ? null : new PaymentSDto()
            {
                FactorNumber = p6.FactorNumber,
                Amount = p6.Amount,
                Description = p6.Description,
                TransactionCode = p6.TransactionCode,
                CardPan = p6.CardPan,
                Authority = p6.Authority,
                Type = p6.Type,
                Status = p6.Status,
                OrderId = p6.OrderId,
                Id = p6.Id,
                CreatedAt = p6.CreatedAt
            };
        }
        public static PaymentSDto AdaptTo(this Payment p7, PaymentSDto p8)
        {
            if (p7 == null)
            {
                return null;
            }
            PaymentSDto result = p8 ?? new PaymentSDto();
            
            result.FactorNumber = p7.FactorNumber;
            result.Amount = p7.Amount;
            result.Description = p7.Description;
            result.TransactionCode = p7.TransactionCode;
            result.CardPan = p7.CardPan;
            result.Authority = p7.Authority;
            result.Type = p7.Type;
            result.Status = p7.Status;
            result.OrderId = p7.OrderId;
            result.Id = p7.Id;
            result.CreatedAt = p7.CreatedAt;
            return result;
            
        }
        public static Expression<Func<Payment, PaymentSDto>> ProjectToSDto => p9 => new PaymentSDto()
        {
            FactorNumber = p9.FactorNumber,
            Amount = p9.Amount,
            Description = p9.Description,
            TransactionCode = p9.TransactionCode,
            CardPan = p9.CardPan,
            Authority = p9.Authority,
            Type = p9.Type,
            Status = p9.Status,
            OrderId = p9.OrderId,
            Id = p9.Id,
            CreatedAt = p9.CreatedAt
        };
        
        private static Order funcMain1(Never p4, Order p5, PaymentSDto p2)
        {
            Order result = p5 ?? new Order();
            
            result.Id = p2.OrderId;
            return result;
            
        }
    }
}