using CMSMicroservice.Application.UserOrderCQ.Queries.GetAllUserOrderByFilter;
using CMSMicroservice.Application.UserOrderCQ.Queries.GetUserOrder;

namespace CMSMicroservice.Application.Common.Mappings;

public class UserOrderProfile : IRegister
{
    void IRegister.Register(TypeAdapterConfig config)
    {
        config.NewConfig<UserOrder,GetUserOrderResponseDto>()
            .Map(dest => dest.Id, src => src.Id)
            .Map(dest => dest.Amount, src => src.Amount)
            .Map(dest => dest.PackageId, src => src.PackageId)
            .Map(dest => dest.TransactionId, src => src.TransactionId)
            .Map(dest => dest.PaymentStatus, src => src.PaymentStatus)
            .Map(dest => dest.PaymentDate, src => src.PaymentDate)
            .Map(dest => dest.UserId, src => src.UserId)
            .Map(dest => dest.UserAddressId, src => src.UserAddressId)
            .Map(dest => dest.PaymentMethod, src => src.PaymentMethod)
            .Map(dest => dest.UserAddressText, src => src.UserAddress.Address)
            .Map(dest => dest.FactorDetails, src => src.FactorDetails.Select(s=>s.Adapt<GetUserOrderResponseFactorDetail>()))
        
            ; 
        
        config.NewConfig<UserOrder,GetAllUserOrderByFilterResponseModel>()
            .Map(dest => dest.Id, src => src.Id)
            .Map(dest => dest.Amount, src => src.Amount)
            .Map(dest => dest.PackageId, src => src.PackageId)
            .Map(dest => dest.TransactionId, src => src.TransactionId)
            .Map(dest => dest.PaymentStatus, src => src.PaymentStatus)
            .Map(dest => dest.PaymentDate, src => src.PaymentDate)
            .Map(dest => dest.UserId, src => src.UserId)
            .Map(dest => dest.UserAddressId, src => src.UserAddressId)
            .Map(dest => dest.PaymentMethod, src => src.PaymentMethod)
            .Map(dest => dest.UserAddressText, src => src.UserAddress.Address)
            .Map(dest => dest.FactorDetails, src => src.FactorDetails.Select(s=>s.Adapt<GetUserOrderResponseFactorDetail>()))
            ;
        
        config.NewConfig<FactorDetails,GetUserOrderResponseFactorDetail>()
            .Map(dest => dest.ProductId, src => src.ProductId)
            .Map(dest => dest.ProductTitle, src => src.Product.Title)
            .Map(dest => dest.ProductThumbnailPath, src => src.Product.ThumbnailPath)
            .Map(dest => dest.UnitPrice, src => src.Product.Price)
            .Map(dest => dest.Count, src => src.Count)
            .Map(dest => dest.UnitDiscountPrice, src => src.Product.Price*(src.Product.Discount/100))
            ;    
        
        config.NewConfig<FactorDetails,GetAllUserOrderByFilterResponseModelFactorDetail>()
            .Map(dest => dest.ProductId, src => src.ProductId)
            .Map(dest => dest.ProductTitle, src => src.Product.Title)
            .Map(dest => dest.ProductThumbnailPath, src => src.Product.ThumbnailPath)
            .Map(dest => dest.UnitPrice, src => src.Product.Price)
            .Map(dest => dest.Count, src => src.Count)
            .Map(dest => dest.UnitDiscountPrice, src => src.Product.Price*(src.Product.Discount/100))
            ;
        
    }
}
