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

import com.jeequan.jeepay.core.interfaces.push.IBaiduBceService;
import com.jeequan.jeepay.core.model.ApiRes;
import com.jeequan.jeepay.core.model.DBBaiduBceConfig;
import com.jeequan.jeepay.core.utils.SpringBeansUtil;
import com.jeequan.jeepay.mch.ctrl.CommonCtrl;
import com.jeequan.jeepay.service.impl.MchAppPushInfoService;
import com.jeequan.jeepay.service.impl.SysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 商户App推送 + 语音播报
 *
 * @author zhuxiao
 *
 * @date 2021-06-16 09:15
 */
@RestController
@RequestMapping("/api/pushinfo")
public class MchAppPushInfoController extends CommonCtrl {

    @Autowired private MchAppPushInfoService mchAppPushInfoService;
    @Autowired private SysConfigService sysConfigService;

    /** 商户app推送设备注册 **/
    @RequestMapping(value = "/register", method = RequestMethod.POST)
    public ApiRes register() {

        // 查询用户app推送设备是否注册
        mchAppPushInfoService.saveMchCid(getReqParamJSON(), getCurrentMchNo(), getCurrentUser().getSysUserId());

        return ApiRes.ok();
    }

    /** 获取百度语音播报token **/
    @RequestMapping(value = "/getBaiduToken", method = RequestMethod.GET)
    public ApiRes getBaiduToken() {

        DBBaiduBceConfig baiduBceConfig = sysConfigService.getDBBaiduBceConfig();
        IBaiduBceService baiduBceService = SpringBeansUtil.getBean("baiduBceService", IBaiduBceService.class);
        return ApiRes.ok(baiduBceService.getBaiduBceToken(baiduBceConfig));
    }

}
