package com.api.controller.v1;

import com.hfkj.channel.lakala.LaKaLaConfigService;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.model.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @className: MerController
 * @author: HuRui
 * @date: 2023/5/23
 **/
@Controller
@Api(value = "公共")
@RequestMapping(value = "/v1/mer")
public class MerController {

    private static Logger log = LoggerFactory.getLogger(MerController.class);

    @Resource
    private LaKaLaConfigService laKaLaConfigService;

    @RequestMapping(value="/wechatParamConf",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "微信参数配置")
    public ResponseData wechatParamConf(@RequestParam(value = "merCupNo" , required = true) String merCupNo,
                                        @RequestParam(value = "channlId" , required = true) String channlId,
                                        @RequestParam(value = "subMchId" , required = true) String subMchId,
                                        @RequestParam(value = "subAppid" , required = false) String subAppid,
                                        @RequestParam(value = "jsapiPath" , required = false) String jsapiPath,
                                        @RequestParam(value = "confType" , required = true) String confType) {
        try {
            // return ResponseMsgUtil.success(laKaLaConfigService.wechatParamConf("822690053111ERC", "569999133","wxf30043187dc90829", "http://api2.ctpark.cn/"));
            return ResponseMsgUtil.success(laKaLaConfigService.wechatParamConf(merCupNo, channlId, subMchId,subAppid, jsapiPath,confType));

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return ResponseMsgUtil.exception(e);
        }
    }

    @RequestMapping(value="/querySubMerInfo",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "querySubMerInfo")
    public ResponseData querySubMerInfo(@RequestParam(value = "channlId" , required = true) String channlId,
                                        @RequestParam(value = "merCupNo" , required = true) String merCupNo) {
        try {

            return ResponseMsgUtil.success(laKaLaConfigService.querySubMerInfo(channlId,merCupNo));

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return ResponseMsgUtil.exception(e);
        }
    }


    @RequestMapping(value="/queryWechatConfig",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "微信服务商子商户开发配置查询")
    public ResponseData queryWechatConfig(@RequestParam(value = "subMchId" , required = true) String subMchId,
                                          @RequestParam(value = "merCupNo" , required = true) String merCupNo) {
        try {

            return ResponseMsgUtil.success(laKaLaConfigService.queryWechatConfig(subMchId,merCupNo));

        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return ResponseMsgUtil.exception(e);
        }
    }
}
