package com.jeesharp.business.modules.mall.application.settle;

import cn.hutool.core.util.StrUtil;
import com.jeesharp.business.modules.finance.api.PayRefundSuccessHandler;
import com.jeesharp.business.modules.finance.paymentrecord.enums.PayRecordBizSceneEnum;
import com.jeesharp.business.modules.mall.application.support.MallAfterSaleRefundCoordinator;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 商城售后退款成功回调，委托 {@link MallAfterSaleRefundCoordinator} 完成售后与退券。
 *
 * @author jeesharp
 * @since 2026-06-11
 */
@Service
@AllArgsConstructor
public class MallPayRefundSuccessHandler implements PayRefundSuccessHandler {

    private final MallAfterSaleRefundCoordinator mallAfterSaleRefundCoordinator;

    @Override
    public boolean supports(String bizScene) {
        return PayRecordBizSceneEnum.MALL_ORDER.getCode().equals(bizScene);
    }

    @Override
    public void onRefundSuccess(String payRefundOrderId, String bizRefId) {
        if (StrUtil.isBlank(bizRefId)) {
            return;
        }
        mallAfterSaleRefundCoordinator.applyRefundSuccess(bizRefId, "SYSTEM", "微信退款成功，自动完成售后");
    }
}
