package com.jeequan.jeepay.mch.ctrl.alipay;

import com.jeequan.jeepay.bizcommons.manage.alipay.AlipayOpenSpOperationManage;
import com.jeequan.jeepay.core.model.ApiRes;
import com.jeequan.jeepay.mch.ctrl.CommonCtrl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/***
* 支付宝设备绑定
*
* @author zx
*
* @date 2023/03/13 15:26
*/
@RestController
@RequestMapping("/api/alipaySpOperation")
public class AlipayOpenSpOperationController extends CommonCtrl {

    @Autowired private AlipayOpenSpOperationManage alipayOpenSpOperationManage;

    /** 获取授权码  **/
    @PreAuthorize("hasAnyAuthority('ENT_MCH_ALIPAY_SP_OPERATION')")
    @GetMapping( "/queryQrcode")
    public ApiRes queryQrcode() {
        return alipayOpenSpOperationManage.queryQrcode(getCurrentMchNo(), getValStringRequired("alipayAccount"));
    }

    /** 发起授权  **/
    @PreAuthorize("hasAnyAuthority('ENT_MCH_ALIPAY_SP_OPERATION')")
    @PostMapping("/apply")
    public ApiRes apply() {
        return alipayOpenSpOperationManage.apply(getCurrentMchNo(), getValStringRequired("alipayAccount"));
    }

    /** 查询支付宝授权结果  **/
    @PreAuthorize("hasAnyAuthority('ENT_MCH_ALIPAY_SP_OPERATION')")
    @GetMapping("/queryResult")
    public ApiRes queryResult() {
        return alipayOpenSpOperationManage.queryResult(getCurrentMchNo());
    }

    /** 查询当前商户支付宝授权信息  **/
    @PreAuthorize("hasAnyAuthority('ENT_MCH_ALIPAY_SP_OPERATION')")
    @GetMapping("/authInfo")
    public ApiRes authInfo() {
        return alipayOpenSpOperationManage.authInfo(getCurrentMchNo());
    }

}
