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.FoodBookingRefundConfirmApplicationService;
import com.jeesharp.business.modules.food.dto.FoodBookingRefundDTO;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 餐饮预订退款成功回调：委托 {@link FoodBookingRefundConfirmApplicationService} 关单。
 *
 * @author jeesharp
 * @since 2026-06-11
 */
@Service
@AllArgsConstructor
public class FoodPayRefundSuccessHandler implements PayRefundSuccessHandler {

    private final FoodBookingRefundConfirmApplicationService foodBookingRefundConfirmApplicationService;

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

    @Override
    public void onRefundSuccess(String payRefundOrderId, String bizRefId) {
        if (StrUtil.isBlank(bizRefId)) {
            return;
        }
        FoodBookingRefundDTO dto = new FoodBookingRefundDTO();
        dto.setOrderId(bizRefId.trim());
        dto.setRefundReason("微信退款成功");
        foodBookingRefundConfirmApplicationService.confirmBookingRefund(dto);
    }
}
