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

import com.jeequan.jeepay.bizcommons.manage.MchPayPassageConfigManage;
import com.jeequan.jeepay.core.aop.MethodLog;
import com.jeequan.jeepay.core.model.ApiRes;
import com.jeequan.jeepay.mch.ctrl.CommonCtrl;
import com.jeequan.jeepay.service.impl.MchPayPassageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/****
* 新版商户支付通道配置ctrl
*
* @author terrfly
* 
* @date 2022/3/30 16:37
*/
@RestController
@RequestMapping("/api/mch/payPassages")
public class MchPayPassageConfigController extends CommonCtrl {

    @Autowired private MchPayPassageService mchPayPassageService;
    @Autowired private MchPayPassageConfigManage mchPayPassageConfigManage;

    /**
     * 支付方式 <--> 通道配置
     * 左侧列表（支付方式）
     *
     * **/
    @GetMapping
    public ApiRes list() {

        String appId = getValStringRequired("appId");
        String wayCode = getValString("wayCode");
        String wayName = getValString("wayName");
        String wayType = getValString("wayType");

        return mchPayPassageConfigManage.queryPaywayList(appId, wayCode, wayName, wayType,null, getIPage());
    }


    /**
     * 支付方式 <--> 通道配置
     * 右侧列表（可用的支付接口）
     *
     * **/
    @GetMapping("/availablePayInterface/{appId}/{wayCode}")
    public ApiRes availablePayInterface(@PathVariable("appId") String appId, @PathVariable("wayCode") String wayCode) {

        return mchPayPassageConfigManage.availablePayInterface(appId, wayCode);
    }


    /**
     * 更新商户使用的通道信息
     */
    @PostMapping("/mchPassage")
    @MethodLog(remark = "更新商户支付通道")
    public ApiRes updatePassage() {

        String appId = getValStringRequired("appId");
        String ifCode = getValStringRequired("ifCode");
        String wayCode = getValStringRequired("wayCode");
        Byte state = getValByteRequired("state");

        mchPayPassageService.updateMchPassageState(appId, wayCode, ifCode, state);
        return ApiRes.ok();

    }

}
