using Google.Protobuf.WellKnownTypes;
using CMSMicroservice.Domain.Enums;
using Mapster;
using AppPt = CMSMicroservice.Application.PaymentTransactionCQ.Queries.GetAllPaymentTransactionByFilter;
using AppPtSummary = CMSMicroservice.Application.PaymentTransactionCQ.Queries.GetPaymentTransactionSummary;
using ProtoPt = CMSMicroservice.Protobuf.Protos.PaymentTransaction;

namespace CMSMicroservice.WebApi.Common.Mappings;

public class PaymentTransactionProfile : IRegister
{
    public void Register(TypeAdapterConfig config)
    {
        config.NewConfig<ProtoPt.GetAllPaymentTransactionByFilterRequest, AppPt.GetAllPaymentTransactionByFilterQuery>()
            .Map(dest => dest.PaginationState, src => src.PaginationState)
            .Map(dest => dest.SortBy, src => src.SortBy)
            .Map(dest => dest.Filter, src => src.Filter);

        config.NewConfig<ProtoPt.GetAllPaymentTransactionByFilterFilter, AppPt.GetAllPaymentTransactionByFilterFilter>()
            .Map(dest => dest.UserId, src => src.UserId)
            .Map(dest => dest.Mobile, src => src.Mobile)
            .Map(dest => dest.GatewayProvider, src => src.GatewayProvider)
            .Map(dest => dest.PaymentStatus, src => src.PaymentStatus)
            .Map(dest => dest.Authority, src => src.Authority)
            .Map(dest => dest.RefId, src => src.RefId)
            .Map(dest => dest.OrderId, src => src.OrderId)
            .Map(dest => dest.CreatedFrom, src => src.CreatedFrom != null ? src.CreatedFrom.ToDateTime() : (DateTime?)null)
            .Map(dest => dest.CreatedTo, src => src.CreatedTo != null ? src.CreatedTo.ToDateTime() : (DateTime?)null);

        config.NewConfig<AppPt.GetAllPaymentTransactionByFilterResponseDto, ProtoPt.GetAllPaymentTransactionByFilterResponse>()
            .Map(dest => dest.MetaData, src => src.MetaData)
            .Map(dest => dest.Models, src => src.Models);

        config.NewConfig<AppPt.GetAllPaymentTransactionByFilterResponseModel, ProtoPt.PaymentTransactionModel>()
            .Map(dest => dest.Id, src => src.Id)
            .Map(dest => dest.UserId, src => src.UserId ?? 0)
            .Map(dest => dest.Mobile, src => src.Mobile ?? string.Empty)
            .Map(dest => dest.GatewayProvider, src => src.GatewayProvider)
            .Map(dest => dest.Amount, src => src.Amount)
            .Map(dest => dest.Authority, src => src.Authority ?? string.Empty)
            .Map(dest => dest.PaymentStatus, src => src.PaymentStatus)
            .Map(dest => dest.VerificationStatusCode, src => src.VerificationStatusCode)
            .Map(dest => dest.VerificationStatusMessage, src => src.VerificationStatusMessage ?? string.Empty)
            .Map(dest => dest.RefId, src => src.RefId ?? string.Empty)
            .Map(dest => dest.CardPan, src => src.CardPan ?? string.Empty)
            .Map(dest => dest.OrderId, src => src.OrderId ?? string.Empty)
            .Map(dest => dest.TransactionId, src => src.TransactionId)
            .Map(dest => dest.Description, src => src.Description ?? string.Empty)
            .Map(dest => dest.CreatedAt, src => Timestamp.FromDateTimeOffset(src.Created));

        config.NewConfig<ProtoPt.GetPaymentTransactionSummaryRequest, AppPtSummary.GetPaymentTransactionSummaryQuery>()
            .Map(dest => dest.Filter, src => src.Filter);

        config.NewConfig<AppPtSummary.GetPaymentTransactionSummaryResponseDto, ProtoPt.GetPaymentTransactionSummaryResponse>()
            .Map(dest => dest.TotalCount, src => src.TotalCount)
            .Map(dest => dest.TotalAmount, src => src.TotalAmount)
            .Map(dest => dest.SuccessfulCount, src => src.SuccessfulCount)
            .Map(dest => dest.PendingCount, src => src.PendingCount);
    }
}
