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

import com.seer.teach.common.utils.MoneyUtil;
import com.seer.teach.pay.admin.withdrawal.controller.request.AdminPayMerchantRevenueDetailReq;
import com.seer.teach.pay.admin.withdrawal.controller.response.AdminPayMerchantRevenueDetailResp;
import com.seer.teach.pay.entity.PayMerchantRevenueDetailEntity;
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 AdminPayMerchantRevenueDetailConvert {

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

    AdminPayMerchantRevenueDetailResp entityToResponse(PayMerchantRevenueDetailEntity payMerchantRevenueDetailEntity);

    List<AdminPayMerchantRevenueDetailResp> entityListToResponseList(List<PayMerchantRevenueDetailEntity> payMerchantRevenueDetailEntityList);

    PayMerchantRevenueDetailEntity reqToEntity(AdminPayMerchantRevenueDetailReq payMerchantRevenueDetailRequest);
    
    /**
     * 在映射完成后，处理需要转换的金额字段
     * @param entity 源对象
     * @param response 目标对象
     */
    @AfterMapping
    default void convertCentToYuan(PayMerchantRevenueDetailEntity entity, @MappingTarget AdminPayMerchantRevenueDetailResp response) {

        if (entity.getActualRevenue() != null) {
            response.setActualRevenue(MoneyUtil.centToYuan(entity.getActualRevenue()));
        }
        if (entity.getRefundAmount() != null) {
            response.setRefundAmount(MoneyUtil.centToYuan(entity.getRefundAmount()));
        }
    }
}