package com.jeesharp.business.pay.notify;

import com.jeesharp.business.pay.service.WechatPayNotifyAdapterService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 杏花村 C 端微信支付成功回调统一入口（{@code /mobile/pay/notify/wechat}）。
 *
 * <p>按微信回调 {@code attach.bizType} 路由至各 {@link com.jeesharp.business.pay.adapter.WechatPayCallbackAdapter}。</p>
 *
 * @author jeesharp
 * @since 2026-06-29
 */
@Slf4j
@RestController
@RequestMapping("${jeesharp.web.mobilePath}/pay/notify")
@Tag(name = "小程序-微信支付回调（统一入口）")
@AllArgsConstructor
public class TravelWechatPayNotifyMobileController {

    private final WechatPayNotifyAdapterService wechatPayNotifyAdapterService;

    @Operation(summary = "微信支付成功回调（全业态统一）")
    @ApiResponses({
        @ApiResponse(responseCode = "204", description = "验签通过，无应答包体（符合微信 V3 要求）"),
        @ApiResponse(responseCode = "400", description = "参数错误，body 含 code=FAIL"),
        @ApiResponse(responseCode = "500", description = "验签失败或处理失败，body 含 code=FAIL")
    })
    @PostMapping("/wechat")
    public ResponseEntity<?> wechatNotify(@RequestHeader Map<String, String> headers,
                                          HttpServletRequest request) {
        return WechatPayNotifyEntryControllerSupport.handleByAttach(
            headers, request, wechatPayNotifyAdapterService, log, "TravelPay");
    }
}
