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)
    {
        // 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);
    }
}

