package cn.pluss.platform.controller.home;

import cn.pluss.platform.pay.PayService;
import cn.pluss.platform.ryx.pay.RyxPayService;
import cn.pluss.platform.sxf.pay.SxfPayService;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.*;


/**
 * 统一接收支付成功异步地址
 */
@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/notify")
public class PayNotifyController {

    @Setter(onMethod_ = {@Autowired, @Qualifier("ysPayOldService")})
    private PayService ysPayOldService;

    @Setter(onMethod_ = {@Autowired, @Qualifier("ysPayService")})
    private PayService ysPayService;

    @Setter(onMethod_ = {@Autowired, @Lazy})
    private SxfPayService sxfPayService;

    @Setter(onMethod_ = {@Autowired, @Lazy})
    private RyxPayService ryxPayService;

    @RequestMapping(value = "/sxfCallBack",method = RequestMethod.POST)
    public Map<String,String> sxfCallBack(@RequestBody Map<String, String> map) {
        log.info("【随行付】异步回调开始，【随行付】回调参数:{}<=====================",JSONObject.toJSONString(map));
        return (Map<String, String>) sxfPayService.payNotifyCallBack(map);
    }

    @RequestMapping(value = "/old/ysCallBack",method = RequestMethod.POST)
    public String oldYsCallBack(@RequestParam Map<String,String> params) {
        log.info("【银盛】旧版接口异步回调开始，【银盛】回调参数:{}<=====================",JSONObject.toJSONString(params));
        return (String) ysPayOldService.payNotifyCallBack(params);
    }

    @RequestMapping(value = "/ysCallBack",method = RequestMethod.POST)
    public String ysCallBack(@RequestParam Map<String,String> params) {
        log.info("【银盛】新版异步回调开始，【银盛】回调参数:{}<=====================",JSONObject.toJSONString(params));
        return (String) ysPayService.payNotifyCallBack(params);
    }
    @RequestMapping(value = "/ryxCallBack",method = RequestMethod.POST)
    public String ryxCallBack(@RequestParam Map<String,String> params) {
        log.info("【瑞银信】异步回调开始，【瑞银信】回调参数:{}<=====================",JSONObject.toJSONString(params));
        return (String) ryxPayService.payNotifyCallBack(params);
    }
}
