package com.cpop.jambox.business.controller.callback;

import com.cpop.jambox.business.service.EasyLearnOrderService;
import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
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;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author DB
 * @version 1.0.0
 * @since 2024-01-20 0:22
 */
@RestController
@Api(tags = "果酱-放心学回调接口")
@RequestMapping("/callback/easyLearn")
public class CallBackEasyLearnController {

    @Autowired
    private EasyLearnOrderService easyLearnOrderService;

    /**
     * 用户签约成功回调
     * @author DB
     * @since 2024/1/20
     * @param notifyData 返回参数
     */
    @ApiOperation("放心学先学后付支付分回调通知")
    @PostMapping("/learnNowPayLaterUserSignPlanNotify")
    public String learnNowPayLaterUserSignPlanNotifyUrl(@RequestBody String notifyData) {
        easyLearnOrderService.learnNowPayLaterUserSignPlanNotify(notifyData);
        return WxPayNotifyResponse.success("成功");
    }

    /**
     * 支付分用户核销成功回调
     * @author DB
     * @since 2024/1/20
     * @param notifyData 返回参数
     */
    @ApiOperation("支付分用户核销成功回调")
    @PostMapping("/userServiceOrderSuccess")
    public String userServiceOrderSuccess(@RequestBody String notifyData) {
        easyLearnOrderService.userServiceOrderSuccess(notifyData);
        return WxPayNotifyResponse.success("成功");
    }

    /**
     * 微信支付订单通知
     * @author DB
     * @since 2023/12/21
     * @param xmlData 数据
     * @return java.lang.String
     */
    @ApiOperation("微信支付订单通知")
    @PostMapping("/notify/oncePay")
    public String oncePayResult(@RequestBody String xmlData){
        easyLearnOrderService.oncePayResult(xmlData);
        return WxPayNotifyResponse.success("成功");
    }

    /**
     * 微信支付联合支付订单通知
     * @param xmlData 数据
     * @return java.lang.String
     */
    @ApiOperation("微信支付联合支付订单通知")
    @PostMapping("/notify/unionPay")
    public String unionPay(@RequestBody String xmlData){
        easyLearnOrderService.unionPayResult(xmlData);
        return WxPayNotifyResponse.success("成功");
    }

    /**
     * 微信支付联合支付普通订单通知
     * @return java.lang.String
     */
    @ApiOperation("微信支付联合支付普通订单通知")
    @PostMapping("/notify/normalUnionPay")
    public String normalUnionPay(HttpServletRequest request, HttpServletResponse response){
        return easyLearnOrderService.normalUnionPay(request,response);
    }
}
