using Google.Protobuf.WellKnownTypes;
using CMSMicroservice.Domain.Enums;
using Mapster;
using AppUp = CMSMicroservice.Application.UserPackagePurchaseCQ.Queries.GetAllUserPackagePurchaseByFilter;
using AppUpSummary = CMSMicroservice.Application.UserPackagePurchaseCQ.Queries.GetUserPackagePurchaseSummary;
using AppRollup = CMSMicroservice.Application.UserPackagePurchaseCQ.Queries.GetCustomerPackagePurchaseRollup;
using ProtoUp = CMSMicroservice.Protobuf.Protos.UserPackagePurchase;

namespace CMSMicroservice.WebApi.Common.Mappings;

public class UserPackagePurchaseProfile : IRegister
{
    public void Register(TypeAdapterConfig config)
    {
        config.NewConfig<ProtoUp.GetAllUserPackagePurchaseByFilterRequest, AppUp.GetAllUserPackagePurchaseByFilterQuery>()
            .Map(dest => dest.PaginationState, src => src.PaginationState)
            .Map(dest => dest.SortBy, src => src.SortBy)
            .Map(dest => dest.Filter, src => src.Filter);

        config.NewConfig<ProtoUp.GetAllUserPackagePurchaseByFilterFilter, AppUp.GetAllUserPackagePurchaseByFilterFilter>()
            .Map(dest => dest.UserId, src => src.UserId)
            .Map(dest => dest.PackageId, src => src.PackageId)
            .Map(dest => dest.PurchaseMethod, src => src.PurchaseMethod == null ? null : (PackagePurchaseMethod?)src.PurchaseMethod)
            .Map(dest => dest.PurchasedFrom, src => src.PurchasedFrom != null ? src.PurchasedFrom.ToDateTime() : (DateTime?)null)
            .Map(dest => dest.PurchasedTo, src => src.PurchasedTo != null ? src.PurchasedTo.ToDateTime() : (DateTime?)null)
            .Map(dest => dest.MinAmount, src => src.MinAmount)
            .Map(dest => dest.MaxAmount, src => src.MaxAmount);

        config.NewConfig<AppUp.GetAllUserPackagePurchaseByFilterResponseDto, ProtoUp.GetAllUserPackagePurchaseByFilterResponse>()
            .Map(dest => dest.MetaData, src => src.MetaData)
            .Map(dest => dest.Models, src => src.Models);

        config.NewConfig<AppUp.GetAllUserPackagePurchaseByFilterResponseModel, ProtoUp.UserPackagePurchaseModel>()
            .Map(dest => dest.Id, src => src.Id)
            .Map(dest => dest.UserId, src => src.UserId)
            .Map(dest => dest.UserName, src => src.UserName)
            .Map(dest => dest.UserMobile, src => src.UserMobile)
            .Map(dest => dest.PackageId, src => src.PackageId)
            .Map(dest => dest.PackageName, src => src.PackageName)
            .Map(dest => dest.PurchaseMethod, src => (int)src.PurchaseMethod)
            .Map(dest => dest.PurchasedAt, src => Timestamp.FromDateTime(DateTime.SpecifyKind(src.PurchasedAt, DateTimeKind.Utc)))
            .Map(dest => dest.Amount, src => src.Amount)
            .Map(dest => dest.OrderId, src => src.OrderId)
            .Map(dest => dest.TransactionId, src => src.TransactionId)
            .Map(dest => dest.CreatedAt, src => Timestamp.FromDateTimeOffset(src.Created));

        config.NewConfig<ProtoUp.GetUserPackagePurchaseSummaryRequest, AppUpSummary.GetUserPackagePurchaseSummaryQuery>()
            .Map(dest => dest.Filter, src => src.Filter);

        config.NewConfig<AppUpSummary.GetUserPackagePurchaseSummaryResponseDto, ProtoUp.GetUserPackagePurchaseSummaryResponse>()
            .Map(dest => dest.TotalCount, src => src.TotalCount)
            .Map(dest => dest.TotalAmount, src => src.TotalAmount);

        config.NewConfig<ProtoUp.GetCustomerPackagePurchaseRollupRequest, AppRollup.GetCustomerPackagePurchaseRollupQuery>()
            .Map(dest => dest.PaginationState, src => src.PaginationState)
            .Map(dest => dest.Filter, src => src.Filter);

        config.NewConfig<ProtoUp.GetCustomerPackagePurchaseRollupFilter, AppRollup.GetCustomerPackagePurchaseRollupFilter>()
            .Map(dest => dest.UserId, src => src.UserId)
            .Map(dest => dest.PurchaseMethod, src => src.PurchaseMethod == null ? null : (PackagePurchaseMethod?)src.PurchaseMethod)
            .Map(dest => dest.PurchasedFrom, src => src.PurchasedFrom != null ? src.PurchasedFrom.ToDateTime() : (DateTime?)null)
            .Map(dest => dest.PurchasedTo, src => src.PurchasedTo != null ? src.PurchasedTo.ToDateTime() : (DateTime?)null);

        config.NewConfig<AppRollup.GetCustomerPackagePurchaseRollupResponseDto, ProtoUp.GetCustomerPackagePurchaseRollupResponse>()
            .Map(dest => dest.MetaData, src => src.MetaData)
            .Map(dest => dest.Models, src => src.Models);

        config.NewConfig<AppRollup.CustomerPackagePurchaseRollupModel, ProtoUp.CustomerPackagePurchaseRollupModel>()
            .Map(dest => dest.UserId, src => src.UserId)
            .Map(dest => dest.UserName, src => src.UserName)
            .Map(dest => dest.UserMobile, src => src.UserMobile)
            .Map(dest => dest.FirstPackageId, src => src.FirstPackageId)
            .Map(dest => dest.FirstPackageName, src => src.FirstPackageName)
            .Map(dest => dest.FirstAmount, src => src.FirstAmount)
            .Map(dest => dest.FirstPurchasedAt, src => Timestamp.FromDateTime(DateTime.SpecifyKind(src.FirstPurchasedAt, DateTimeKind.Utc)))
            .Map(dest => dest.LastPackageId, src => src.LastPackageId)
            .Map(dest => dest.LastPackageName, src => src.LastPackageName)
            .Map(dest => dest.LastAmount, src => src.LastAmount)
            .Map(dest => dest.LastPurchasedAt, src => Timestamp.FromDateTime(DateTime.SpecifyKind(src.LastPurchasedAt, DateTimeKind.Utc)))
            .Map(dest => dest.LastPurchaseMethod, src => (int)src.LastPurchaseMethod)
            .Map(dest => dest.PurchaseCount, src => src.PurchaseCount)
            .Map(dest => dest.TotalAmount, src => src.TotalAmount)
            .Map(dest => dest.DayaCount, src => src.DayaCount)
            .Map(dest => dest.DayaAmount, src => src.DayaAmount)
            .Map(dest => dest.ManualCount, src => src.ManualCount)
            .Map(dest => dest.ManualAmount, src => src.ManualAmount)
            .Map(dest => dest.GatewayCount, src => src.GatewayCount)
            .Map(dest => dest.GatewayAmount, src => src.GatewayAmount);
    }
}
