using CMSMicroservice.Application.PackageCQ.Commands.PurchaseGoldenPackage;
using CMSMicroservice.Application.PackageCQ.Commands.VerifyGoldenPackagePurchase;
using CMSMicroservice.Application.PackageCQ.Commands.InitiateBasePackagePayment;
using CMSMicroservice.Application.PackageCQ.Commands.VerifyBasePackagePayment;
using CMSMicroservice.Application.PackageCQ.Queries.GetUserPackageStatus;
using CMSMicroservice.Protobuf.Protos.Package;
using Google.Protobuf.WellKnownTypes;

namespace CMSMicroservice.WebApi.Common.Mappings;

public class PackageProfile : IRegister
{
    void IRegister.Register(TypeAdapterConfig config)
    {
        // PurchaseGoldenPackage
        config.NewConfig<PurchaseGoldenPackageRequest, PurchaseGoldenPackageCommand>()
            .Map(dest => dest.UserId, src => src.UserId)
            .Map(dest => dest.PackageId, src => src.PackageId)
            .Map(dest => dest.ReturnUrl, src => src.ReturnUrl);

        config.NewConfig<PurchaseGoldenPackageResponseDto, PurchaseGoldenPackageResponse>()
            .Map(dest => dest.Success, src => src.Success)
            .Map(dest => dest.Message, src => src.Message)
            .Map(dest => dest.OrderId, src => src.OrderId)
            .Map(dest => dest.PaymentGatewayUrl, src => src.PaymentGatewayUrl)
            .Map(dest => dest.TrackingCode, src => src.TrackingCode);

        // VerifyGoldenPackagePurchase
        config.NewConfig<VerifyGoldenPackagePurchaseRequest, VerifyGoldenPackagePurchaseCommand>()
            .Map(dest => dest.OrderId, src => src.OrderId)
            .Map(dest => dest.Authority, src => src.Authority)
            .Map(dest => dest.Status, src => src.Status);

        config.NewConfig<VerifyGoldenPackagePurchaseResponseDto, VerifyGoldenPackagePurchaseResponse>()
            .Map(dest => dest.Success, src => src.Success)
            .Map(dest => dest.Message, src => src.Message)
            .Map(dest => dest.OrderId, src => src.OrderId)
            .Map(dest => dest.TransactionId, src => src.TransactionId)
            .Map(dest => dest.ReferenceCode, src => src.ReferenceCode)
            .Map(dest => dest.WalletBalance, src => src.WalletBalance);

        // GetUserPackageStatus
        config.NewConfig<GetUserPackageStatusRequest, GetUserPackageStatusQuery>()
            .Map(dest => dest.UserId, src => src.UserId);

        config.NewConfig<UserPackageStatusDto, GetUserPackageStatusResponse>()
            .Map(dest => dest.UserId, src => src.UserId)
            .Map(dest => dest.PackagePurchaseMethod, src => src.PackagePurchaseMethod)
            .Map(dest => dest.HasPurchasedPackage, src => src.HasPurchasedPackage)
            .Map(dest => dest.IsClubMemberActive, src => src.IsClubMemberActive)
            .Map(dest => dest.WalletBalance, src => src.WalletBalance)
            .Map(dest => dest.DiscountBalance, src => src.DiscountBalance)
            .Map(dest => dest.CanActivateClubMembership, src => src.CanActivateClubMembership)
            .Map(dest => dest.LastOrderNumber, src => src.LastOrderNumber != null ? src.LastOrderNumber : null)
            .Map(dest => dest.LastPurchaseDate, src => src.LastPurchaseDate.HasValue 
                ? Timestamp.FromDateTime(src.LastPurchaseDate.Value.ToUniversalTime()) 
                : null);
        
        // InitiateBasePackagePayment (56M پکیج پایه)
        config.NewConfig<InitiateBasePackagePaymentRequest, InitiateBasePackagePaymentCommand>()
            .Map(dest => dest.UserId, src => src.UserId);

        config.NewConfig<InitiateBasePackagePaymentResponseDto, InitiateBasePackagePaymentResponse>()
            .Map(dest => dest.Success, src => src.Success)
            .Map(dest => dest.Message, src => src.Message)
            .Map(dest => dest.OrderId, src => src.OrderId)
            .Map(dest => dest.TransactionId, src => src.TransactionId)
            .Map(dest => dest.Amount, src => src.Amount);

        // VerifyBasePackagePayment (تأیید پرداخت پکیج پایه)
        config.NewConfig<VerifyBasePackagePaymentRequest, VerifyBasePackagePaymentCommand>()
            .Map(dest => dest.OrderId, src => src.OrderId)
            .Map(dest => dest.TransactionId, src => src.TransactionId)
            .Map(dest => dest.PaymentSuccess, src => src.PaymentSuccess)
            .Map(dest => dest.RefId, src => src.RefId)
            .Map(dest => dest.Message, src => src.Message);

        config.NewConfig<VerifyBasePackagePaymentResponseDto, VerifyBasePackagePaymentResponse>()
            .Map(dest => dest.Success, src => src.Success)
            .Map(dest => dest.Message, src => src.Message)
            .Map(dest => dest.OrderId, src => src.OrderId)
            .Map(dest => dest.TransactionId, src => src.TransactionId)
            .Map(dest => dest.ReferenceCode, src => src.ReferenceCode)
            .Map(dest => dest.WalletBalance, src => src.WalletBalance)
            .Map(dest => dest.DiscountBalance, src => src.DiscountBalance);
    }
}

