package com.seer.teach.pay.admin.withdrawal.convert;

import com.seer.teach.common.utils.MoneyUtil;
import com.seer.teach.pay.admin.withdrawal.controller.request.PayWithdrawalBalanceReq;
import com.seer.teach.pay.admin.withdrawal.controller.response.PayWithdrawalBalanceResp;
import com.seer.teach.pay.entity.PayMerchantAccountEntity;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.factory.Mappers;

import java.math.BigDecimal;
import java.util.List;

@Mapper
public interface PayWithdrawalBalanceConvert {

    PayWithdrawalBalanceConvert INSTANCE = Mappers.getMapper(PayWithdrawalBalanceConvert.class);

    PayWithdrawalBalanceResp entityToResponse(PayMerchantAccountEntity payUserWithdrawalBalanceEntity);

    List<PayWithdrawalBalanceResp> entityListToResponseList(List<PayMerchantAccountEntity> payUserWithdrawalBalanceEntityList);

    PayMerchantAccountEntity reqToEntity(PayWithdrawalBalanceReq payUserWithdrawalBalanceRequest);
    
    /**
     * 在映射完成后，将分转换为元
     * @param entity 源对象
     * @param response 目标对象
     */
    @AfterMapping
    default void convertCentToYuan(PayMerchantAccountEntity entity, @MappingTarget PayWithdrawalBalanceResp response) {
        if (entity.getAvailableBalance() != null) {
            response.setAvailableBalance(MoneyUtil.centToYuan(entity.getAvailableBalance()));
        }
        if (entity.getFrozenBalance() != null) {
            response.setFrozenBalance(MoneyUtil.centToYuan(entity.getFrozenBalance()));
        }
        if (entity.getTotalSettledAmount() != null) {
            response.setTotalSettledAmount(MoneyUtil.centToYuan(entity.getTotalSettledAmount()));
        }
    }
}