package com.jeesharp.business.modules.food.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.food.application.support.FoodPersonalMealRefundCoordinator;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 个人订餐退款成功回调：关单并回滚菜品已售数量。
 *
 * @author jeesharp
 * @since 2026-06-11
 */
@Service
@AllArgsConstructor
public class FoodMealPayRefundSuccessHandler implements PayRefundSuccessHandler {

    private final FoodPersonalMealRefundCoordinator foodPersonalMealRefundCoordinator;

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

    @Override
    public void onRefundSuccess(String payRefundOrderId, String bizRefId) {
        if (StrUtil.isBlank(bizRefId)) {
            return;
        }
        foodPersonalMealRefundCoordinator.applyRefundSuccess(bizRefId.trim(), "微信退款成功", null, null);
    }
}
