package com.jeesharp.business.pay.notify;

import com.jeesharp.business.modules.food.application.FoodCompanyMealApplicationService;
import com.jeesharp.business.modules.food.application.FoodPersonalMealApplicationService;
import com.jeesharp.business.modules.food.dto.FoodMealOrderRefundSuccessDTO;
import com.jeesharp.framework.pojo.AjaxResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("${jeesharp.web.mobilePath}/food/meal/order/refund/notify")
@Tag(name = "小程序-订餐退款回调")
@AllArgsConstructor
public class FoodMealRefundNotifyMobileController {

    private static final String ORDER_TYPE_PERSONAL = "personal";
    private static final String ORDER_TYPE_COMPANY = "company";

    private final FoodPersonalMealApplicationService foodPersonalMealApplicationService;
    private final FoodCompanyMealApplicationService foodCompanyMealApplicationService;

    @Operation(summary = "退款成功回调")
    @PostMapping("/success")
    public AjaxResult<Void> refundSuccess(@RequestBody @Valid FoodMealOrderRefundSuccessDTO dto) {
        if (ORDER_TYPE_PERSONAL.equals(dto.getOrderType())) {
            foodPersonalMealApplicationService.handleRefundSuccess(dto);
        } else if (ORDER_TYPE_COMPANY.equals(dto.getOrderType())) {
            foodCompanyMealApplicationService.handleRefundSuccess(dto);
        } else {
            return AjaxResult.failMsg("订单类型无效");
        }
        return AjaxResult.ok("处理成功");
    }
}
